Problems Adding Contact with Primary Company Association via API

Hi,

I was hoping someone could help me with an issue I keep running into. To summarize, I am trying to add contacts to hubspot using the contacts Create API and add a primary association to a company hubspot ID that is different than the company auto-populated by Hubspot for the contact. I would still like to keep the auto-populated company as a secondary association too if possible.

To summarize the steps that lead to my issue:

1. Create a contact using the contacts API that auto populates a company (company A) within hubspot (with auto company association turned on). Ref: Accounts Dashboard | HubSpot

2. Immediately after (or during contact creation) associate another company (company B) hubspot ID to the contact as primary using the associationId: 1. Ref: Accounts Dashboard | HubSpot

3. Within hubspot, contact’s primary company is the one that hubspot auto-generated (company A) rather than the one I explicitly tried to make the primary company (company B).

Anyone else facing this issue?

Thanks!

Isabela

Hi @isabelareid,

I am seeing the same behaviour, regardless of including the association data in my initial contact create request the auto generated company becomes the primary. To get around this I wait until I get a response back and then make another request to the CRM Associations endpoint and can successfully set the primary company as desired. Requests and output below for reference:

Request 1: Create Contact and associate company

{
 "properties": {
 "company": "Tesla",
 "email": "emusk@tesla.com",
 "firstname": "Elon",
 "lastname": "Musk"
 },
 "associations": [
 {
 "to": {
 "id": "8109465573"
 },
 "types": [
 {
 "associationCategory": "HUBSPOT_DEFINED",
 "associationTypeId": 1
 }
 ]
 }
 ]
}

RESPONSE 201
{
 "id": "252",
 "properties": {
 "company": "Tesla",
 "createdate": "2023-08-07T08:13:52.614Z",
 "email": "emusk@tesla.com",
 "firstname": "Elon",
 "hs_all_contact_vids": "252",
 "hs_email_domain": "tesla.com",
 "hs_is_contact": "true",
 "hs_is_unworked": "true",
 "hs_lifecyclestage_lead_date": "2023-08-07T08:13:52.614Z",
 "hs_marketable_status": "false",
 "hs_marketable_until_renewal": "false",
 "hs_object_id": "252",
 "hs_object_source": "INTEGRATION",
 "hs_object_source_id": "1914406",
 "hs_pipeline": "contacts-lifecycle-pipeline",
 "lastmodifieddate": "2023-08-07T08:13:52.614Z",
 "lastname": "Musk",
 "lifecyclestage": "lead"
 },
 "createdAt": "2023-08-07T08:13:52.614Z",
 "updatedAt": "2023-08-07T08:13:52.614Z",
 "archived": false
}

After the request checking the CRM results in the auto-generated company (Tesla) being set as the primary and Marvel being a secondary association:

Request 2: Update association to set primary company

PUT https://api.hubapi.com/crm/v4/objects/contact/252/associations/company/8109465573
BODY
[
 {
 "associationCategory": "HUBSPOT_DEFINED",
 "associationTypeId": 1
 }
]

RESPONSE 201
{
 "fromObjectTypeId": "0-1",
 "fromObjectId": 252,
 "toObjectTypeId": "0-2",
 "toObjectId": 8109465573,
 "labels": [
 "Primary"
 ]
}

After the request Marvel is the primary company and Tesla becomes the secondary company:

I hope this helps!

Hey @coldrickjack!

Thanks for confirming you’re seeing the same on your side. After some testing using your suggested solution, if the calls between contact creation and primary assocation creation are too close together - hubspot will still make the auto-generated company primary. My guess is this has something to do with hubspots API implementation which always(?) makes the auto generated company primary regardless if there’s an existing association, most likely due to database sync delays? For now, I’ve just added sleeps as a workaround. Do you know where I could go to submit this as a bug?

Thanks for your help!

Isabela

Hi @isabelareid,

No problem. Sorry I couldn’t be of more help! The best place to submit a bug would be to report it to the frontline support team (assuming you are using Starter, Professional or Enterprise). Instructions on how to do that can be found here.

Thank you! And no worries you are still of great help!