# Associate a deal with a company using the php sdk.

**URL:** <https://community.hubspot.com/t/associate-a-deal-with-a-company-using-the-php-sdk/78331>\
**Category:** APIs & Integrations\
**Tags:** php, object\
**Created:** [March 29, 2023, 7:41pm UTC](https://community.hubspot.com/t/associate-a-deal-with-a-company-using-the-php-sdk/78331 "2023-03-29T19:41:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ROliver8](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@ROliver8](https://community.hubspot.com/u/ROliver8)\
**Post date:** [March 29, 2023, 7:41pm UTC](https://community.hubspot.com/t/associate-a-deal-with-a-company-using-the-php-sdk/78331/1 "2023-03-29T19:41:45Z")

</div>

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

```lia-code-sample
$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

```lia-code-sample
// 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

---

<div class="post-metadata">

**Author:** ![skimura](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@skimura](https://community.hubspot.com/u/skimura)\
**Post date:** [March 30, 2023, 2:01am UTC](https://community.hubspot.com/t/associate-a-deal-with-a-company-using-the-php-sdk/78331/2 "2023-03-30T02:01:14Z")

</div>

@ROliver8

Hi.

How about this ?

```lia-code-sample
$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](https://github.com/HubSpot/hubspot-api-php/blob/master/codegen/Crm/Deals/Api/AssociationsApi.php#L413)

So, generate `AssociationSpec` instance.

> <https://github.com/HubSpot/hubspot-api-php/blob/master/codegen/Crm/Deals/Model/AssociationSpec.php#L199>

(And use constant）

`public const ASSOCIATION_CATEGORY_HUBSPOT_DEFINED = 'HUBSPOT_DEFINED';`

> <https://github.com/HubSpot/hubspot-api-php/blob/master/codegen/Crm/Deals/Model/AssociationSpec.php#L168>

In my case, it works.

Thanks.

---

<div class="post-metadata">

**Author:** ![ROliver8](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@ROliver8](https://community.hubspot.com/u/ROliver8)\
**Post date:** [March 30, 2023, 3:07pm UTC](https://community.hubspot.com/t/associate-a-deal-with-a-company-using-the-php-sdk/78331/3 "2023-03-30T15:07:47Z")

</div>

Skirmura,

Thank You! This worked perfectly.
