v3 Contact Create API Throws Error On Duplicate Email Address

SOLVE
New Contributor

I have a situation where at a certain point in my web application, I need to create some contacts in HubSpot. These contacts are not submitting a form and this is not caused by an action on their part. If the contacts already exist in HubSpot I want them to be updated with the information I have in my system. I need to also associate these contacts with a known company id once they are created/updated. There shouldn't be more than 5 contacts I need to create at a time. 

 

I thought I could use the v3 Contact Create API endpoint for this but despite what the docs imply both the individual and batch versions give an error if you provide an email address that is already assigned to a contact. I attempted to use the old "contacts/v1/contact/batch/" API which handles the deduplication correctly but does not give me the resulting contact ids I need to associate them with the company.

 

Any suggestions on how to do this? My current plan is to use the v3 batch retrieve contact API to tell which emails exist and which don't and then call create with the new ones and update with the existing ones. But I am hoping there is an easier way.

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Solution
Regular Contributor

I use: https://legacydocs.hubspot.com/docs/methods/contacts/create_or_update . Because it is a guaranteed atomic upsert which cannot screw up a contact, to do the create, and the hubspot_owner_id field or the V3 assoc APIs to make any needed assoc updates.

 

Unfortunately, only Contact has a guaranteed safe upsert, and not any other object, and only in the obsolete API. There is some "idProperty" stuff in the V3 API which is supposed to help, but it is not working yet and gives errors when you try it, last time I checked. This is something I badly wanted to see fixed, because the current approach has a TOCTTOU vulnerability aka race condition.

View solution in original post

Reply
0 Upvotes
4 Replies 4
Community Manager

Hello @mayflowervenues ,

As a heads up, that funtionality will be added to the V3 endpoint before the V1 is deprecated.

@btsp , how would you suggest going about this?

Thanks,

Dennis


We are excited to announce that the Community will be launching a weekly newsletter on November 2, 2020!
Sign up today!
Reply
0 Upvotes
Solution
Regular Contributor

I use: https://legacydocs.hubspot.com/docs/methods/contacts/create_or_update . Because it is a guaranteed atomic upsert which cannot screw up a contact, to do the create, and the hubspot_owner_id field or the V3 assoc APIs to make any needed assoc updates.

 

Unfortunately, only Contact has a guaranteed safe upsert, and not any other object, and only in the obsolete API. There is some "idProperty" stuff in the V3 API which is supposed to help, but it is not working yet and gives errors when you try it, last time I checked. This is something I badly wanted to see fixed, because the current approach has a TOCTTOU vulnerability aka race condition.

View solution in original post

Reply
0 Upvotes
New Contributor

Thanks for the response. I am going to go with your suggestion and use the legacy API for upserting individual contacts and then use the V3 batch association API to associate them with the Company. I will let you know how it goes.

 

Not sure what you meant by using "hubspot_owner_id" because that seems to be the HubSpot User that owns the contact, not the company.  I do hope there is a batch API for upserting contacts soon. You might also consider changing the V3 docs so that the "Deduplication" section does not imply that the V3 API allows creating contacts that are already in the system. 

Reply
0 Upvotes
Regular Advisor | Gold Partner

Hi @mayflowervenues !

 

Yes, if you are okay with using legacy and v3 api's together then create or update endpoint is the approach you can follow.

But if you want to go with v3 only, you can search the contact using /v3/objects/contacts/search  

 

Regards,

Himanshu

Reply
0 Upvotes