I’m using the hubspot-api-php package
Trying to call the update endpoint
PATCH
/crm/v3/objects/contacts/{contactId}
This is what the hubspot developer docs uses as an example:
<?php
use HubSpot\Factory;
use HubSpot\Client\Crm\Contacts\ApiException;
$client = Factory::createWithApiKey("YOUR_HUBSPOT_API_KEY");
$properties = [
"company" => "Biglytics",
"email" => "bcooper@biglytics.net",
"firstname" => "Bryan",
"lastname" => "Cooper",
"phone" => "(877) 929-0687",
"website" => "biglytics.net"
];
$SimplePublicObjectInput = new SimplePublicObjectInput(['properties' => $properties]);
try {
$apiResponse = $client->crm()->contacts()->basicApi()->update("433380577", $SimplePublicObjectInput);
var_dump($apiResponse);
} catch (ApiException $e) {
echo "Exception when calling basic_api->update: ", $e->getMessage();
}
This is my implementation:
function update_contact( $contact_id, $properties )
{
$client = Factory::createWithAccessToken(get_option('hs_api'));
$SimplePublicObjectInput = new SimplePublicObjectInput(['properties' => $properties]);
try {
$apiResponse = $client->crm()->contacts()->basicApi()->update($contact_id, $SimplePublicObjectInput);
error_log(print_r($apiResponse,true));
} catch (ApiException $e) {
error_log("Exception when calling basic_api->update: ". $e->getMessage());
}
}
Note that $properties looks like this when inspected:
Array
(
[address] => 123 Main St
[address_2] => P.O. 12
[city] => Vancouver
[email] => email@example.com
[firstname] => Kyle
[lastname] =>
[mobilephone] => (877) 929-0687
[province] =>
[zip] =>
)
This is the response:
Exception when calling basic_api->update: [400] Client error: `PATCH https://api.hubapi.com/crm/v3/objects/contacts/[the contact id]` resulted in a `400 Bad Request` response:
{"status":"error","message":"No properties found to update, please provide at least one.","correlationId":"be4a7ab7-2069 (truncated...)
The endpoint with the same properties and contact id works when using Postman, and also when using the “test call” feature in the API documentation.
Am I doing something wrong?