# Creating An Association In Custom Code Workflow

**URL:** <https://community.hubspot.com/t/creating-an-association-in-custom-code-workflow/66349>\
**Category:** APIs & Integrations\
**Tags:** workflows\
**Created:** [October 3, 2022, 12:43pm UTC](https://community.hubspot.com/t/creating-an-association-in-custom-code-workflow/66349 "2022-10-03T12:43:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Swallow](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/james_swallow/32/97852_2.png) [@James\_Swallow](https://community.hubspot.com/u/James_Swallow)\
**Post date:** [October 3, 2022, 12:43pm UTC](https://community.hubspot.com/t/creating-an-association-in-custom-code-workflow/66349/1 "2022-10-03T12:43:24Z")

</div>

Hi all.

Can some kind person point out what I’m doing wrong with the code below on my custom workflow? Everything else in my code works, but once I try an update, I’m hit with all sorts of erros no matter how much I tweak.

hubspotClient.crm.objects.associationsApi.create({

“fromObjectId”: contact\_id,  
“toObjectId”: found\_company\_id,  
“category”: “HUBSPOT\_DEFINED”,  
“definitionId”: 1,  
“associationType”: “contact\_to\_company”  
}  
)

Many thanks in advance

---

<div class="post-metadata">

**Author:** ![LeeBartelme](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/leebartelme/32/95647_2.png) [@LeeBartelme](https://community.hubspot.com/u/LeeBartelme)\
**Post date:** [October 3, 2022, 1:15pm UTC](https://community.hubspot.com/t/creating-an-association-in-custom-code-workflow/66349/2 "2022-10-03T13:15:53Z")

</div>

Pretty sure you want this:

`hubspotClient.crm.objects.associationsApi.create(contact_id,found_company_id,"HUBSPOT_DEFINED",1,"contact_to_company")`

The function expects individual arguments, not an object. See [example](https://github.com/HubSpot/hubspot-api-nodejs#example-create-contact-company-and-associate-created-objects) documentation.

---

<div class="post-metadata">

**Author:** ![James\_Swallow](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/james_swallow/32/97852_2.png) [@James\_Swallow](https://community.hubspot.com/u/James_Swallow)\
**Post date:** [October 4, 2022, 11:42am UTC](https://community.hubspot.com/t/creating-an-association-in-custom-code-workflow/66349/3 "2022-10-04T11:42:48Z")

</div>

Hi Lee.

Thanks loads for the help. Between your feedback and a colleague I got there. It’s:

```lia-code-sample
hubspotClient.crm.objects.associationsApi.create("CONTACT",contact_id,"COMPANY",found_company_id,"contact_to_company",1)

}

```

The main reason I was having issues was due to the fact that the you must explicitly state what the object type is before providing its ID number. I’d been trying this and it was still failing until I realised it’s case sensitive and must be in capitals, so ‘CONTACT’ and ‘COMPANY’ work.

Thanks for pointing me in the right direction Lee

---

<div class="post-metadata">

**Author:** ![AStoyanov](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@AStoyanov](https://community.hubspot.com/u/AStoyanov)\
**Post date:** [March 8, 2023, 8:44am UTC](https://community.hubspot.com/t/creating-an-association-in-custom-code-workflow/66349/4 "2023-03-08T08:44:01Z")

</div>

I know this thread may be old, but I was able to make it work by using only this syntax:

`hubspotClient.crm.objects.associationsApi.create("contacts",contactId,"companies", companyId, 'contact_to_company' )`

I thought for both companies and contacts the default object type is “contact” and “company” but it depends on how exactly your objects are named. In my case my objecst are “companies” and “contacts”.  
Hope that helps!
