Skip to content

Instantly share code, notes, and snippets.

@jackcoldrick90
Created February 16, 2022 12:37
Show Gist options
  • Save jackcoldrick90/b26f3cf3f26d9bce9d2e96270771117f to your computer and use it in GitHub Desktop.
Save jackcoldrick90/b26f3cf3f26d9bce9d2e96270771117f to your computer and use it in GitHub Desktop.
This code will create a contact off the back of a form submission whereby a user is prompted to provide details for a plus 1.
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
const fname = event.inputFields['firstname'];
const lname = event.inputFields['lastname'];
const plus1FirstName = event.inputFields['plus_1_first_name'];
const plus1LastName = event.inputFields['plus_1_last_name'];
const plus1EmailAddress = event.inputFields['plus_1_email_address'];
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
const properties = {
"email": plus1EmailAddress,
"firstname": plus1FirstName,
"lastname": plus1LastName,
"plus_1_for": fname + " " + lname
};
const SimplePublicObjectInput = {
properties
};
try {
const ApiResponse = await hubspotClient.crm.contacts.basicApi.create(SimplePublicObjectInput);
callback({
outputFields: {
"plus1": plus1FirstName + " " + plus1LastName
}
});
} catch (err) {
console.error(err);
throw err;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment