APIs & Integrations

James_Swallow
Participante

Creating An Association In Custom Code Workflow

resolver

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 Avaliação positiva
1 Solução aceita
James_Swallow
Solução
Participante

Creating An Association In Custom Code Workflow

resolver

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

Exibir solução no post original

0 Avaliação positiva
3 Respostas 3
AStoyanov
Participante

Creating An Association In Custom Code Workflow

resolver

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 Avaliação positiva
James_Swallow
Solução
Participante

Creating An Association In Custom Code Workflow

resolver

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 Avaliação positiva
LeeBartelme
HubSpot Employee
HubSpot Employee

Creating An Association In Custom Code Workflow

resolver

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.