APIs & Integrations

rossm
Member

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?

 

https://developers.hubspot.com/changelog/simplifying-batch-update-response-codes-for-crm-v3-apis

 

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!

21 Replies 21
JasonHessley
Member

Best way to handle 409 Conflict in Batch Contact Create

Checking in with the same issue in 2023. 

 

I'd like it if the batch create would create or update if exists, if HS decides to address this.

0 Upvotes
Sachavskyi
Contributor | Elite Partner
Contributor | Elite Partner

Best way to handle 409 Conflict in Batch Contact Create

@dennisedson any news here?

0 Upvotes
hpolice
Participant

Best way to handle 409 Conflict in Batch Contact Create

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

0 Upvotes
CCasey2
Participant

Best way to handle 409 Conflict in Batch Contact Create

I can try to help. I found that my entire batch WAS failing. So I was batching 100 contacts at a time and if one contact had a malformed email address, it would fail my entire batch. I essentially just parsed the 409 response to find the failing contact and removed them from the batch. Resent the request and the entire batch gets created. 


One thing to note, this post is about duplicate emails. I'm not entirely sure if duplicate emails vs. malformed emails behave the same way. I am using Python to remove my duplicates before I send my batches to this endpoint to create my contacts  

0 Upvotes
CCasey2
Participant

Best way to handle 409 Conflict in Batch Contact Create

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? 

0 Upvotes
mmeow
Member

Best way to handle 409 Conflict in Batch Contact Create

lmao

0 Upvotes
JLai8
Member

Best way to handle 409 Conflict in Batch Contact Create

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

0 Upvotes
Sachavskyi
Contributor | Elite Partner
Contributor | Elite Partner

Best way to handle 409 Conflict in Batch Contact Create

Any news about this?

0 Upvotes
RHZaman
Member

Best way to handle 409 Conflict in Batch Contact Create

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

d_hackelman
Participant

Best way to handle 409 Conflict in Batch Contact Create

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

0 Upvotes
zaklein
Contributor | Diamond Partner
Contributor | Diamond Partner

Best way to handle 409 Conflict in Batch Contact Create

Hi @dennisedson 

Any update on this one?

Thanks,

Zach

dennisedson
HubSpot Product Team
HubSpot Product Team

Best way to handle 409 Conflict in Batch Contact Create

@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 🤞

zaklein
Contributor | Diamond Partner
Contributor | Diamond Partner

Best way to handle 409 Conflict in Batch Contact Create

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

dennisedson
HubSpot Product Team
HubSpot Product Team

Best way to handle 409 Conflict in Batch Contact Create

I put the question back out there to the team 🤞

vimto
Member

Best way to handle 409 Conflict in Batch Contact Create

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 

dennisedson
HubSpot Product Team
HubSpot Product Team

Best way to handle 409 Conflict in Batch Contact Create

Hi @vimto ,

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

0 Upvotes
aastashov
Participant

Best way to handle 409 Conflict in Batch Contact Create

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. 🤞

Sachavskyi
Contributor | Elite Partner
Contributor | Elite Partner

Best way to handle 409 Conflict in Batch Contact Create

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",
....
}
]

 

dennisedson
HubSpot Product Team
HubSpot Product Team

Best way to handle 409 Conflict in Batch Contact Create

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

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Best way to handle 409 Conflict in Batch Contact Create

@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!

0 Upvotes