Associate a deal with a company using the php sdk.

I am using the latest version of the hubspot-sdk-php. I am attempting to create to associate a deal to a company with the following code snippet

$assoc = $this->crmService->crm()
 ->deals()
 ->associationsApi()
 ->create(
 '12768168454',
 'company',
 '15237024337',
 [
 'association_category' => 'HUBSPOT_DEFINED',
 'association_type_id' => 5
 ]
 );

$this->crmService is a valid instance of the hubspot client. The deail and company ids are valid object ids. I am getting the following error

// This is from the hubspot api log
{"status":"error","message":"Invalid input JSON on line 1, column 1: Cannot deserialize value of type `java.util.HashSet<com.hubspot.inbounddb.associations.base.AssociationSpec>` from Object value (token `JsonToken.START_OBJECT`)","correlationId":"5ce66222-a847-4311-978f-1a688b9bcba2"}

//This is the app error I get as a response

HubSpot\Client\Crm\Deals\ApiException: [400] Client error: `PUT https://api.hubapi.com/crm/v4/objects/deals/12768212567/associations/company/15237024337` resulted in a `400 Bad Request` response:
{"status":"error","message":"Invalid input JSON on line 1, column 1: Cannot deserialize value of type `java.util.HashSet (truncated...)
 in /var/www/html/vendor/hubspot/api-client/codegen/Crm/Deals/Api/AssociationsApi.php on line 442

I believe the association spec is wrong but I can not figure out what is wrong. Any help would be appreciated

@ROliver8

Hi.

How about this ?

$associationSpec = new AssociationSpec([
 'association_category' => AssociationSpec::ASSOCIATION_CATEGORY_HUBSPOT_DEFINED,
 'association_type_id' => 5,
]);

$hubspot->crm()->deals()->associationsApi()
 ->create(
 $dealId,
 'company',
 $companyId,
 [
 $associationSpec,
 ]
 );

Function `create` needs `AssociationSpec[]`.

https://github.com/HubSpot/hubspot-api-php/blob/master/codegen/Crm/Deals/Api/AssociationsApi.php#L413

So, generate `AssociationSpec` instance.

(And use constant)

public const ASSOCIATION_CATEGORY_HUBSPOT_DEFINED = 'HUBSPOT_DEFINED';

In my case, it works.

Thanks.

Skirmura,

Thank You! This worked perfectly.