Create Associations When Calling /crm/v3/objects/contacts/batch/upsert

Are you not also able to create associations when upserting? Seems deficient. I tried adding an associations object, but it appears it was ignored.

When calling the v3 or v4 associations endpoint, can you reference the objects by their unique identifier instead of HubSpot ID? I tried adding idProperty, but it still doesn’t recognize the unique id.

Hey, @Anya23 :waving_hand: Thanks for your questions. For Q1, I have another thread with folks having issues using unique IDs and the Upsert endpoint. Can you share a simple request, response, and error message, please? For Q2, the documentation doesn’t offer unique ID as an option for adding or requesting associations.

Thanks for the additional info. — Jaycee

@Jaycee_Lewis I was able to referene a unique property when upserting a custom object, but as with @Anya23 here, the associations seems to be ignored.

The associations are available on the update/create batch requests but seems to have been missed off on this endpoint.

I am seeing the same issue. The upsert will update/create the contact, but no associations are made. In my case I am trying to associate a contact to a custom object. Here is an example body:

{inputs: [
 {
 "idProperty": "email",
 "id": "melissa@gmail.com",
 "properties": { "email": "melissa@gmail.com" },
 "associations": [
 {
 "types": [
 { "associationCategory": "USER_DEFINED", "associationTypeId": 57 }
 ],
 "to": { "id": "12345" }
 }
 ]
 },
 {
 "idProperty": "email",
 "id": "corey@gmail.com",
 "properties": { "email": "corey@gmail.com" },
 "associations": [
 {
 "types": [
 { "associationCategory": "USER_DEFINED", "associationTypeId": 57 }
 ],
 "to": { "id": "12345" }
 }
 ]
 }
]}

Did you get an answer on this? when i call batch update, the association is also ignored. this is problematic because if i upsert a new contact, hubspot by default will create a company with the domain, which could be not the company’s actual domain. if i don’t let hubspot create a company automatically, if someone were to create a contact in the UI, it will not have a company. love your experience.

When using the batch upsert endpoint for contacts, there appears to be a discrepancy between the documented functionality and actual implementation regarding associations. The issue is likely that associations require both objects to exist before the association can be created. While the upsert endpoint creates/updates the contact, the association creation appears to be failing silently.

Here are a few approaches you could try:

Split your operation into two API calls:

First, use the batch upsert endpoint to create/update contacts

Then, use the associations endpoint to create the relationships once you have the contact IDs

Consider using the CRM Associations API specifically:

POST /crm/v4/associations/{fromObjectType}/{fromObjectId}/{toObjectType}/{toObjectId}/{associationTypeId}

Check if you’re using the correct association type ID for your custom object. For custom objects, you may need to use a specific association type ID that matches your schema.

Thank you. Indeed. The downside of separating into two steps, is that you then need to disable the automatic creation of companies based on domain, because some contacts have a different email than the company, e.g. contacts could have a regional email, e.g. example.co.uk<> while the main domain is example.com<>. If we first created example.com<>, and then later upsert bob@example.co.uk, specifying the association to example.com, I was hoping, as the documentation says, that example.co.uk<> company would not be created. If upsert doesn’t work with association, then we have to disable automatic creation of companies based on domain. And then worry about creation of contacts that don’t have a company and then create a company via a script.