v3 Contact Create API Throws Error On Duplicate Email Address
SOLVE
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.
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.
v3 Contact Create API Throws Error On Duplicate Email Address
SOLVE
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.
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.