Create bulk association between one contact to multiple companies

Base on message from MaggieB here, we are now able to create association contact to multiple companies: https://community.hubspot.com/t5/HubSpot-Ideas/Associate-one-contact-to-multiple-companies/idi-p/19236

In this page, we also have associtation with primary company and non-primary company by UI Associate records

But when I tried to do that with API, it raise an exception error:

Conflicting one-to-one association: Association{fromObjectId=5657, toObjectId=7797520586, associationCategory=HUBSPOT_DEFINED, associationTypeId=1

I provide a screenshot from postman

Above example is when I tried to create associations from contact id

5657 to company id

7797566184 and

7797520586

The association type I inputted is 1 (contact-to-company). Any missing steps that I did or invalid params that I’ve made? Thank you!

Hey, @MNaufal :waving_hand: Thanks for the great question. You got yourself so close. Let’s get the rest of the way there :ship:

The best first step when working with the v4 Associations API is to double-check your labels and their IDs. If we make a request here —GET /crm/v4/associations/{fromObjectType}/{toObjectType}/labels , we’ll get the IDs and any labels, if applicable. In this case, we see that for the HubSpot defined associations, 1 = Primary. In my request, 279 (no label) was returned as the other HubSpot defined Contact to Company association.

{
 "results": [
 {
 "category": "USER_DEFINED",
 "typeId": 27,
 "label": "Test 1"
 },
 {
 "category": "HUBSPOT_DEFINED",
 "typeId": 279,
 "label": null
 },
 {
 "category": "USER_DEFINED",
 "typeId": 31,
 "label": "Vendor"
 },
 {
 "category": "HUBSPOT_DEFINED",
 "typeId": 1,
 "label": "Primary"
 },
 {
 "category": "USER_DEFINED",
 "typeId": 29,
 "label": "Nacho guy"
 }
 ]
}

Knowing this, I recreated your request using my test account —

Contact (Mort) with no associated companies

Request:

curl --request POST \
 --url https://api.hubapi.com/crm/v4/associations/contact/company/batch/create \
 --header 'authorization: Bearer YOUR_ACCESS_TOKEN' \
 --header 'content-type: application/json' \
 --data '{
 "inputs": [
 {
 "from": {
 "id": "1601"
 },
 "to": {
 "id": "16053398365"
 },
 "types": [
 {
 "associationCategory": "HUBSPOT_DEFINED",
 "associationTypeId": 1
 }
 ]
 },
 {
 "from": {
 "id": "1601"
 },
 "to": {
 "id": "10202231613"
 },
 "types": [
 {
 "associationCategory": "HUBSPOT_DEFINED",
 "associationTypeId": 279
 }
 ]
 }
 ]
}'

Response:

HTTP 201

{
 "status": "COMPLETE",
 "results": [
 {
 "fromObjectTypeId": "0-1",
 "fromObjectId": 1601,
 "toObjectTypeId": "0-2",
 "toObjectId": 10202231613,
 "labels": []
 },
 {
 "fromObjectTypeId": "0-1",
 "fromObjectId": 1601,
 "toObjectTypeId": "0-2",
 "toObjectId": 16053398365,
 "labels": [
 "Primary"
 ]
 }
 ],
 "startedAt": "2023-06-13T16:40:57.595Z",
 "completedAt": "2023-06-13T16:40:57.663Z"
}

Mort with Primary and an associated company

I hope this helps get you moving forward! — Jaycee

Thank you! I tried it and it works. Do you know how do I get the list of it? because in this link I couldn’t found the 279 code. Thank you!

Hey, @MNaufal :waving_hand: I am glad to know that worked! There is not a matching list in this case. You’ll need to make the request to the endpoint to get both the HubSpot and User-defined associations and IDs.

With the v1 version of these endpoints, the endpoints don’t utilize custom associations, so it was possible to give a fixed list. Like what you linked to. But with the updated endpoints, they allow users to create and use custom associations, which can have IDs unique to a portal.

This makes publishing an inclusive list impossible. This is based on my read of the documentation and not defined anywhere I can find.

Legacy endpoints — fixed associations, provides a list of all associations IDs.

Updated endpoints — allows for custom associations, doesn’t provide a list of all IDs, does provide an endpoint to query the IDs, both default and custom.

Whew, that probably more than you asked for :blush: And I hope it’s helpful!

Best,

Jaycee

I see, no other way then. thank you!