HubSpot API PHP Client Libraries for V3 - Create a contact with associations

I try to create a new contact and to associat this contact with an existing company ID.

Here is my code :

$contactInput = new \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectWithAssociations();
$contactInput->setProperties([
‘salutation’ => $genre1,
‘lastname’ => $nom1,
‘firstname’ => $prenom1,
‘job_function’ => $fonction1,
‘phone’ => $tel1,
‘mobilephone’ => $mobile1,
‘email’ => $email1
]);
$contactInput->setAssociations([
‘to’ => [‘id’ => $idsociete],
‘types’ => [‘associationCategory’ => “HUBSPOT_DEFINED”, ‘associationTypeId’ => 279]
]);
$contact = $hubspot->crm()->contacts()->basicApi()->create($contactInput);

AND here is the error message :

Fatal error: Uncaught HubSpot\Client\Crm\Contacts\ApiException: [400] Client error: `POST https://api.hubapi.com/crm/v3/objects/contacts\` resulted in a `400 Bad Request` response: {“status”:“error”,“message”:"Invalid input JSON on line 1, column 278: Cannot deserialize value of type `java.util.Array (truncated…) in /homepages/15/d475713241/htdocs/code-events-tools/SETT24/vendor/hubspot/api-client/codegen/Crm/Contacts/Api/BasicApi.php:393 Stack trace: 0 /homepages/15/d475713241/htdocs/code-events-tools/SETT24/vendor/hubspot/api-client/codegen/Crm/Contacts/Api/BasicApi.php(369): HubSpot\Client\Crm\Contacts\Api\BasicApi->createWithHttpInfo() 1 /homepages/15/d475713241/htdocs/code-events-tools/SETT24/api_hubspot.php(275): HubSpot\Client\Crm\Contacts\Api\BasicApi->create() #2 {main} thrown in /homepages/15/d475713241/htdocs/code-events-tools/SETT24/vendor/hubspot/api-client/codegen/Crm/Contacts/Api/BasicApi.php on line 393

Can you help me to fix this?

Hey, @TCOLINS :waving_hand: That error looks like it’s unhappy with how you are setting up your associations. If you try using the on-page example here — Contacts API, do you get the same error?

Best,

Jaycee

Hi Jaycee

Thanks for your answer.

I don’t see the page you’re talking about.

Maybe the link is missing…

Tanguy

Here you go Accounts Dashboard | HubSpot It won’t link directly to the endpoints tab, you’ll need to do that manually.

Best,

Jaycee

I read your linked page and I check my code but I don’t find where is the problem… Have you got any idea ?

Thanks

Tanguy