Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HubSpotHanevold/ff3c0e61abb34a50ed5dd19e98882a22 to your computer and use it in GitHub Desktop.
Save HubSpotHanevold/ff3c0e61abb34a50ed5dd19e98882a22 to your computer and use it in GitHub Desktop.
const request = require('request');
exports.main = async (event, callback) => {
/* BE SURE TO ADD THE CONTACT ID INTO THE 'PROPERTY TO INCLUDE IN CODE' SECTION OF THE CUSTOM CODED ACTION */
const contact_id = event.inputFields['hs_object_id'];
/* LOOK UP THE CONTACT VIA THE ID AND RETRIEVE THE PROPERTY 'hs_additional_emails' */
var options = {
"method": "GET",
"url": "https://api.hubapi.com/crm/v3/objects/contacts/" + contact_id + "?hapikey=" + process.env.HAPIKEY + "&properties=hs_additional_emails"
};
let secondary_exists = true;
request(options, function (error, response, body) {
const obj = JSON.parse(body);
/* GATHER THE SECONDARY EMAIL VALUE */
let secondary_email = obj.properties.hs_additional_emails;
/* IF THERE ISN'T A VALUE FOR SECONDARY EMAIL ADDRESS, SET IT AS "NO VALUE" */
if(secondary_email == null) {
secondary_exists = false;
secondary_email = "No Value";
}
/* DON'T FORGET TO ADD THE TWO CALLBACK OUTPUT FIELDS INTO THE DATA OUTPUTS SECTION OF YOUR CUSTOM CODED ACTION. YOU CAN USE THESE VALUES TO DETERMINE NEXT STEPS IN YOUR WORKFLOW */
callback({
outputFields: {
secondary_email: secondary_email,
secondary_exists: secondary_exists,
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment