Best way to handle 409 Conflict in Batch Contact Create

I was writing some code to gracefully handle a 409 Conflict when sending a batch create contact request. I originally assumed that “at least one” of the contacts in the batch must be conflicted and that if I parsed the error response, I could determine the email address causing the conflict, “remove” that item from the batch and retry the request. In this way I could “clean up” the request until it worked. What I found was that, in a batch of more than one contact where at least one was a conflict, but others were not, the “non-conflicted” item(s) DOES get created, even though the request itself returns a 409.

This led to the issue of not knowing WHICH contacts got created and which did not get created. Is there a reason that that the batch create could not return a 207 Multi-status?

This link implies that a batch update SHOULD return a 207 if only partially successful but that does not seem to apply to a 409. In fact, the behavior of that endpoint differs in that the ENTIRE request fails if there is a conflict.

So, in summary:

Batch-creating multiple contacts “partially” succeeds even when one of the contacts encounters a conflict - but returns an error.

Batch-updating multiple contacts “entirely fails” when there is one single conflict.

My struggle with the way it works now is that an error is returned, but the the request may have “worked” all except for one item. In a normal situation I would have some kind of successful response that could be logged, etc. In this case I have a 409 response and the hope that “most of” of the contacts got created.

Am I thinking about this the wrong way?

Thanks for any feedback!

Hi guys! I’m trying to use HubSpot batch API and have the next problem: when I send 3 contacts to https://api.hubapi.com/crm/v3/objects/contact/batch/create and if one of these contacts has a problem - HubSpot response format is like this:

{ "status": "error", "message": "Property values were not valid: ......." "correlationId": "2c2b03e3-5692-4261-b462-0bea1952e562", "category": "VALIDATION_ERROR"}

Why the response format is not like this:

[ { "status": "error", .... }, { "id": "4136413868", .... }, { "id": "4136413870", .... }]

Hi @Sachavskyi ,

This question was just asked by @rossm on Monday. I am asking the team about this. I am going to merge these into one thread so we keep them together

@Sachavskyi , @rossm ,

Looks like this has already been logged as an issue. I do not have a firm date on when it will be addressed, though. Thanks again for flagging!

Hi, is there any update on this issue? We would like to use batch API because we have many contacts to update and we are hitting rate limits.

However, batch update/create does not return errors for individual entities, so we are forced to first try to create an entity then get error about already existing one and use ID to update it.
We would like to send batch create request, get list of already existing IDs and then perform batch update, so that we send less requests to Hubspot API.

hey @rossm

Thanks for adding this question!

I am bringing this up with the team to discuss. Once I have something, I will get back to you :grin:

I barely found this top because it sounds like a recommendation, not a problem. But I think that the problem is the same as mine.

When trying to update a pack of objects, if there are conflicts in one of the objects, HubSpot gives 409 instead of the expected 207.

Our integration service with HubSpot collects changes to objects and once in N time makes a batch request. And now, we see a lot of duplicate errors, because, at error 409, the service does not understand which objects HubSpot was able to update and which are not.
Example request:

{{baseUrl}}/crm/v3/objects/contacts/batch/update?hapikey=<hapikey>
{
 "inputs": [
 {
 "id": "501",
 "properties": {
 "email": "alexander_2@gmail.com" # duplicate
 }
 },
 {
 "id": "551",
 "properties": {
 "email": "alexander_2@gmail.com"
 }
 }
 ]
}

And response:

Status: 409 Conflict
{
 "status": "error",
 "message": "A contact with the email 'alexander_2@gmail.com' already exists.. Existing ID: 551",
 "correlationId": "f41edb07-25bf-4340-af3c-3313d09d16f6",
 "category": "CONFLICT"
}

To avoid synchronization problems, I had to disable batch requests, but this will increase the number of requests to the HubSpot API and affect the limits.

I hope that this problem will be solved soon. :crossed_fingers:

I’ve just encountered this issue now and it’s disheatening to find a thread from Nov 2020 with no clear solution. Seems like this should definitely be a 207 response!

I feel a bit caught out as I’ve coded a solution using this API and now suddenly find myself feeling like the batch endpoints aren’t fit for purpose which are the main endpoints I need!

Weird how the error message I recieved has even less information in it than what @aastashov posted.

{
 "status": "error",
 "message": "Contact already exists. Existing ID: 31401",
 "correlationId": "14342612-8f27-4d22-b1fa-cb161e0d4e08",
 "category": "CONFLICT"
}

To get the email to be able to identify the offending record I need to parse the error message to get the HubSpot ID and then use that to fetch the contact details with another API request…

I’ve noticed this issue is not just limited to conflicts either. I’m having the same thing happen for validation errors that are returning 400 responses. Yep, I’m going to have to do the same as aastashov and disable batch requests. They’re unsuable in their current state.

@dennisedson do we have an update on this?

Hi @vimto ,

I do apologize for your frustration. I flagged this again with the team.

Hi @dennisedson

My colleagues and I have just stumbled across this problem as well.

Is there any timeline you can share on a planned fix / update to this issue?

Thanks very much,

Zach

I put the question back out there to the team :crossed_fingers:

Hi @dennisedson

Any update on this one?

Thanks,

Zach

@zaklein , there was an issue created on that repo for this, but I was informed that there is no timeline on the fix. They split up a product group so one owns the contacts object so hopefully sooner than later :crossed_fingers:

Any update to this issue? We would like to be able to use the error messages + status codes as part of the API logic.

Any update on this issue? Have been looking around for a while to this duplicate problem for batch request.

Any news about this?

Any updates here? Attempting to batch update and create contacts, and the error messages are very unhelpful to determine which contact objects have been created successfully or unsuccessfully

lmao

How does this not have an answer yet? It was asked in 2020 originally and it’s 2023 and I am running into the same issue without being able to find an answer?

Any update on this issue? Have been looking around for a solution to this duplicate problem for batch request.