# Problems Adding Contact with Primary Company Association via API

**URL:** <https://community.hubspot.com/t/problems-adding-contact-with-primary-company-association-via-api/86883>\
**Category:** APIs & Integrations\
**Tags:** companies, contacts\
**Created:** [August 5, 2023, 4:54pm UTC](https://community.hubspot.com/t/problems-adding-contact-with-primary-company-association-via-api/86883 "2023-08-05T16:54:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![isabelareid](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@isabelareid](https://community.hubspot.com/u/isabelareid)\
**Post date:** [August 5, 2023, 4:54pm UTC](https://community.hubspot.com/t/problems-adding-contact-with-primary-company-association-via-api/86883/1 "2023-08-05T16:54:20Z")

</div>

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](https://developers.hubspot.com/docs/api/crm/contacts)

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](https://developers.hubspot.com/docs/api/crm/associations)

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

---

<div class="post-metadata">

**Author:** ![coldrickjack](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/coldrickjack/32/6684_2.png) [@coldrickjack](https://community.hubspot.com/u/coldrickjack)\
**Post date:** [August 7, 2023, 8:36am UTC](https://community.hubspot.com/t/problems-adding-contact-with-primary-company-association-via-api/86883/2 "2023-08-07T08:36:07Z")

</div>

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**

```lia-code-sample
{
 "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:

 ![Screenshot 2023-08-07 at 09.31.01.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/c/c/ccb715fdd4573b62a7137bbe87cd8734d1447dab.png)

**Request 2: Update association to set primary company**

```lia-code-sample
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:

 ![Screenshot 2023-08-07 at 09.30.21.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/8/7/874b7b09d2e8f86a1a5ef72366633d6cf6f9315d.png)

I hope this helps!

---

<div class="post-metadata">

**Author:** ![isabelareid](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@isabelareid](https://community.hubspot.com/u/isabelareid)\
**Post date:** [August 7, 2023, 6:03pm UTC](https://community.hubspot.com/t/problems-adding-contact-with-primary-company-association-via-api/86883/3 "2023-08-07T18:03:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![coldrickjack](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/coldrickjack/32/6684_2.png) [@coldrickjack](https://community.hubspot.com/u/coldrickjack)\
**Post date:** [August 7, 2023, 6:45pm UTC](https://community.hubspot.com/t/problems-adding-contact-with-primary-company-association-via-api/86883/4 "2023-08-07T18:45:20Z")

</div>

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](https://knowledge.hubspot.com/account/get-help-with-hubspot).

---

<div class="post-metadata">

**Author:** ![isabelareid](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@isabelareid](https://community.hubspot.com/u/isabelareid)\
**Post date:** [August 7, 2023, 8:29pm UTC](https://community.hubspot.com/t/problems-adding-contact-with-primary-company-association-via-api/86883/5 "2023-08-07T20:29:58Z")

</div>

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