v3 Contact Create API Throws Error On Duplicate Email AddressSOLVE
Oct 28, 2020 5:53 PM - edited Oct 28, 2020 5:59 PM
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.
Solved! Go to Solution.
Oct 29, 2020 8:28 PM
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.