The scenario is like this. I need to update or create a contact through the api, but I need to determine whether the contact exists through the email field, so I don’t know whether to update the contact or create the contact, so I need the corresponding api
Search by ID and specify email to be the custom ID. NodeJS example:
try {
return await hubspotClient.crm.contacts.basicApi.getById(
email,
['email'],
undefined,
undefined,
false,
'email'
)
} catch(e) {
// Will throw a 404 when no user so catch and return undefined (or ensure not 404 and throw)
return undefined
}
}
I recommend that over the search API as there is a delay in the search engine population so if you try to search, create, search again you may find that the contact has yet to show up in the search resulting in a create error.