Skip to content

Instantly share code, notes, and snippets.

@isaidspaghetti
Last active February 9, 2021 20:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaidspaghetti/cd9633bb18c48f66845b5059f2613c96 to your computer and use it in GitHub Desktop.
Save isaidspaghetti/cd9633bb18c48f66845b5059f2613c96 to your computer and use it in GitHub Desktop.
Index createHubspotContact
//backend/routes/index.js:10
async function createHubspotContact(firstName, lastName, email) {
let hubspotContact;
try {
hubspotContact = await axios.get(`https://api.hubapi.com/crm/v3/objects/contacts/${email}/?idProperty=email&hapikey=${hubspotKey}`);
}
catch {
hubspotContact = await axios.post(`https://api.hubapi.com/crm/v3/objects/contacts?hapikey=${hubspotKey}`,
{
properties: {
'firstname': firstName,
'lastname': lastName,
'email': email,
}
}
);
}
return hubspotContact.data.id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment