APIs & Integrations

James_Swallow
Participant

Creating An Association In Custom Code Workflow

SOLVE

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

 

 

0 Upvotes
1 Accepted solution
James_Swallow
Solution
Participant

Creating An Association In Custom Code Workflow

SOLVE

Hi Lee.

 

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

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

View solution in original post

0 Upvotes
3 Replies 3
AStoyanov
Participant

Creating An Association In Custom Code Workflow

SOLVE

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!

0 Upvotes
James_Swallow
Solution
Participant

Creating An Association In Custom Code Workflow

SOLVE

Hi Lee.

 

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

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

0 Upvotes
LeeBartelme
HubSpot Employee
HubSpot Employee

Creating An Association In Custom Code Workflow

SOLVE

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 documentation.