API Create contact belonging to a Company

SOLVE
New Contributor

Hi

 

When creating new contacts by the api, I also need to set some kind of relation between the contact and company the contact belongs to, right? The contact should have something like a CompanyId or something. What property sets that relation?

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
HubSpot Moderator

Hi @hubsp 

 

This association is done using our CRM Associations API found here: https://developers.hubspot.com/docs/methods/crm-associations/crm-associations-overview

 

As you can see in the documentation, this API allows you to create associations between objects and in this specific case, we'd be looking at the following:

Request URL:

PUT https://api.hubapi.com/crm-associations/v1/associations?hapikey=demo

Sample Body:

{
  "fromObjectId": CONTACT_ID,
  "toObjectId": COMPANY_ID,
  "category": "HUBSPOT_DEFINED",
  "definitionId": 1
}

Once this is done, we'll see that the Contact is correctly associated based on the above request. 

 

I hope this helps!

Matthew Willson

HubSpot Developer Support
1 Reply 1
Highlighted
HubSpot Moderator

Hi @hubsp 

 

This association is done using our CRM Associations API found here: https://developers.hubspot.com/docs/methods/crm-associations/crm-associations-overview

 

As you can see in the documentation, this API allows you to create associations between objects and in this specific case, we'd be looking at the following:

Request URL:

PUT https://api.hubapi.com/crm-associations/v1/associations?hapikey=demo

Sample Body:

{
  "fromObjectId": CONTACT_ID,
  "toObjectId": COMPANY_ID,
  "category": "HUBSPOT_DEFINED",
  "definitionId": 1
}

Once this is done, we'll see that the Contact is correctly associated based on the above request. 

 

I hope this helps!

Matthew Willson

HubSpot Developer Support