# How to set multiple associations between 2 entities?

**URL:** <https://community.hubspot.com/t/how-to-set-multiple-associations-between-2-entities/95677>\
**Category:** Data Hub\
**Created:** [December 8, 2023, 1:08pm UTC](https://community.hubspot.com/t/how-to-set-multiple-associations-between-2-entities/95677 "2023-12-08T13:08:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DCozens](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@DCozens](https://community.hubspot.com/u/DCozens)\
**Post date:** [December 8, 2023, 1:08pm UTC](https://community.hubspot.com/t/how-to-set-multiple-associations-between-2-entities/95677/1 "2023-12-08T13:08:37Z")

</div>

I need to set multiple associations between a Contact and a Company via a workflow using the API

I have a contact that I need to mark as PrimaryContact and BillingContact. This works fine via the Hubspot UI, but when I try to set an additional association via the API it overwrites the first association

The example below results in 1 association against the company

`const fromObjectType = "companies";const fromObjectId = companyToAssociate;const toObjectType = "contact";const toObjectId = contactIdToAssociate;`

`const AssociationSpec = [{ "associationCategory": "USER_DEFINED", "associationTypeId": 124, }];const createContactAssociationResponse = await hubspotClient.apiRequest({ method: 'PUT', path: `/crm/v4/objects/${fromObjectType}/${fromObjectId}/associations/${toObjectType}/${toObjectId}`, body: AssociationSpec});const AssociationSpec2 = [{ "associationCategory": "USER_DEFINED", "associationTypeId": 113, }];const createContactAssociationResponse2 = await hubspotClient.apiRequest({ method: 'PUT', path: `/crm/v4/objects/${fromObjectType}/${fromObjectId}/associations/${toObjectType}/${toObjectId}`, body: AssociationSpec2});`

---

<div class="post-metadata">

**Author:** ![PamCotton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pamcotton/32/47916_2.png) [@PamCotton](https://community.hubspot.com/u/PamCotton)\
**Post date:** [December 8, 2023, 8:12pm UTC](https://community.hubspot.com/t/how-to-set-multiple-associations-between-2-entities/95677/2 "2023-12-08T20:12:51Z")

</div>

Hello @DCozens thank you for posting in our Community!

Associations represent the relationships between objects and activities in the HubSpot CRM. Record associations can exist between records of different objects (e.g., Contact to Company), as well as within the same object (e.g., Company to Company). You can use the associations endpoints to create, retrieve, update, or delete associations between records, or records and activities.

I want to share this developer [doc here with more information.](https://developers.hubspot.com/docs/api/crm/associations)

And invite our top experts @Anton, and @Kevin-C any recommendations to @DCozens.

Thank you,

Pam

---

<div class="post-metadata">

**Author:** ![DCozens](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@DCozens](https://community.hubspot.com/u/DCozens)\
**Post date:** [December 10, 2023, 11:06am UTC](https://community.hubspot.com/t/how-to-set-multiple-associations-between-2-entities/95677/3 "2023-12-10T11:06:31Z")

</div>

OK, so I solved this by myself.

When you PUT the associations for an entity and you need multiple labelled associations between the same two entities, you need to send an array of all the associations. This will overwrite any associations previous applied between the two entities

---

<div class="post-metadata">

**Author:** ![PamCotton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pamcotton/32/47916_2.png) [@PamCotton](https://community.hubspot.com/u/PamCotton)\
**Post date:** [December 12, 2023, 8:07pm UTC](https://community.hubspot.com/t/how-to-set-multiple-associations-between-2-entities/95677/4 "2023-12-12T20:07:19Z")

</div>

Hello @DCozens, thank you very much for sharing how you solved it with us.

Kindly,

Pam
