APIs & Integrations

James_Swallow
Participant

Creating An Association In Custom Code Workflow

Résolue

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 Votes
1 Solution acceptée
James_Swallow
Solution
Participant

Creating An Association In Custom Code Workflow

Résolue

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

Voir la solution dans l'envoi d'origine

0 Votes
3 Réponses
AStoyanov
Participant

Creating An Association In Custom Code Workflow

Résolue

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 Votes
James_Swallow
Solution
Participant

Creating An Association In Custom Code Workflow

Résolue

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 Votes
LeeBartelme
HubSpot Employee
HubSpot Employee

Creating An Association In Custom Code Workflow

Résolue

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.