Association contact to a company

Good morning,
I'm trying to associate a contact to a company with V4 APIs

var client = new RestClient("https://api.hubapi.com/crm/v4/objects/contacts/5139150/associations/0-1/13751153040");var request = new RestRequest(Method.PUT);request.AddHeader("accept", "application/json");request.AddHeader("content-type", "application/json");request.AddHeader("authorization", "Bearer pat-na1-75287a6f-e79b-4c2b-b992-5e48fb4ef961");request.AddParameter("application/json", "[{\"associationCategory\":\"HUBSPOT_DEFINED\",\"associationTypeId\":1}]", ParameterType.RequestBody);IRestResponse response = client.Execute(request);The contact Id is Good The compagny Id is Good I'm testing with Endpoints from HubSpotIn return I have the following message Do you have an idea of ​​the problem by advance THANKS

HTTP 400

{
“status”: “error”,
“message”: “One or more associations are invalid”,
“correlationId”: “c322688e-aabc-43f2-8eef-adcdc788ff87”,
“context”: {
“INVALID_OBJECT_IDS”: [
“CONTACT=13751153040 is not valid”
]
},
“category”: “VALIDATION_ERROR”
}

Hey, @JeanAMOROS :waving_hand: Based on what you shared, I’d start by looking at how your request URL is set up.

You have

https://api.hubapi.com/crm/v4/objects/contacts/5139150/associations/0-1/13751153040

But, if you are associating Contact > Company, it should be

https://api.hubapi.com/crm/v4/objects/contacts/5139150/associations/0-2/13751153040"

Your example is trying to set an association Contact to Contact (0-1) instead of Contact to Company (0-2).

Here’s my example:

  • I have a Contact named Teddy

  • I have a Company called Teddy’s

  • I am using this endpoint
    PUT /crm/v4/objects/{objectType}/{objectId}/associations/{toObjectType}/{toObjectId}​

  • My request

    curl --request PUT \
     --url https://api.hubapi.com/crm/v4/objects/contacts/1501/associations/companies/13861282304 \
     --header 'authorization: Bearer YOUR_ACCESS_TOKEN' \
     --header 'content-type: application/json' \
     --data '[
     {
     "associationCategory": "HUBSPOT_DEFINED",
     "associationTypeId": 1
     }
    ]'​
    
  • The response

    HTTP 201
    
    {
     "fromObjectTypeId": "0-1",
     "fromObjectId": 1501,
     "toObjectTypeId": "0-2",
     "toObjectId": 13861282304,
     "labels": [
     "Primary"
     ]
    }​
    
  • And the association is set as expected :tada:

Have fun building! — Jaycee

Hello Jaycee,
Thank you for your reply.
The association works perfectly.

Cordially

Hey Jean,
I’m David from the hapily support team! We have an app called Associ8 that could make those associations for you. No code required! It makes associations in a workflow action based on search parameters set by you. Check it out here.
If you have any questions or need help setting up, feel free to reach out! I’d be happy to hop on a call with you.
Best,
-David Staat