APIs & Integrations

dmcewen
Participant

Create Contact and associate to Company in one call

Prior to this week I was able to create a Contact and associate it to a Company through the "associatedcompanyid" property in a single HTTP POST request to the URL, https://api.hubapi.com/crm/v3/objects/contacts.


I'd like to avoid having to make 2 API calls to create the Contact and associate it to the Company. Is there another way to acheive this?

 

Here's an example body of the POST request:

 

{
 "properties": {
  "firstname": "...",
  "lastname": "...",
  "associatedcompanyid": "4712632717"
 }
}

 

 

What's happening now, is that we are receiving a successful response from the Contact create call, with the associatedcompanyid property set, however, the Contact is not associated with the Company.

 

{
"id": "2351",
 "properties": {
  "associatedcompanyid": "4712632717",
  "createdate": "...",
  "firstname": "...",
  "hs_is_unworked": "true",
  "hs_marketable_until_renewal": "false",
  "lastname": "..."
 },
"createdAt": "...",
"updatedAt": "...",
}

 

 

This can be seen in the UI or through GET Contact API call, which returns a blank associatedcompanyid and no associations.
https://api.hubapi.com/crm/v3/objects/contacts/2351?archived=false&properties=firstname,lastname,ema...

 

{
  "id": "2351",
  "properties": {
   "associatedcompanyid": "",
   "createdate": "...",
   "email": null,
   "firstname": "...",
   "hs_additional_emails": null,
   "hs_object_id": "2351",
   "lastmodifieddate": "...",
   "lastname": "..."
  },
  "createdAt": "...",
  "updatedAt": "...",
  "archived": false
}

 

0 Upvotes
6 Replies 6
avantassel
Participant

Create Contact and associate to Company in one call

I get a 404 error trying to associate a contact and company,

 

[404] Client error: `PUT https://api.hubapi.com/crm/v3/objects/contacts/101/associations/companies/6769685342/contact_to_comp...` resulted in a `404 Not Found`

 

Using this call,

https://github.com/HubSpot/hubspot-api-php/blob/master/codegen/Crm/Contacts/Api/AssociationsApi.php#...

 

Does this look correct?

 

$this->hubSpot->crm()->contacts()->associationsApi()->create($contact['hubspot_id'], \HubSpot\Crm\ObjectType::COMPANIES, $company['hubspot_id'], 'contact_to_company');

 

0 Upvotes
quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Create Contact and associate to Company in one call

@dmcewenOn my side with the sdk for the api V3 it works well, so there is no reason it don't work when querying directly the api endpoint. Can you try to add the field associatedcompanyid as integer and not as string ?
And verify that the id you use really exist in your company list


0 Upvotes
quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Create Contact and associate to Company in one call

Well, seems that all is ok in you request. So i will wait that the test i made is finished and i post here my answer.


dmcewen
Participant

Create Contact and associate to Company in one call

Thanks @quentin_lamamy . I will add that the Contact creates successfully, it's just not associated to the Company. This same request has worked for the past several months, but within the past week it doesn't associate the Contact to the Company.

0 Upvotes
quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Create Contact and associate to Company in one call

Hi @dmcewen ,

i just run a test on associating contact and company with this field, it will need a times to process, while waiting can you provide us the request and the answer in the call-log of your api key ? You can get it in settings > integrations > apikey. It will help us to understand what is going wrong.


0 Upvotes
dmcewen
Participant

Create Contact and associate to Company in one call

Hi @quentin_lamamy,

 

I was originally using OAuth to connect to the HubSpot instance. I tested it with the API key and had the same result. In the call log you can see from the screenshot below that both the Request and Response tabs do not have any data in them.

 

Screenshot_4.png

0 Upvotes