Skip to content

Instantly share code, notes, and snippets.

@li0nel
Created July 19, 2017 14:22
Show Gist options
  • Save li0nel/3774a96e61da93a30a00285460f8c014 to your computer and use it in GitHub Desktop.
Save li0nel/3774a96e61da93a30a00285460f8c014 to your computer and use it in GitHub Desktop.
fetch('https://api.hubapi.com/companies/v2/companies/' + inputData.companyId+ '/contacts?hapikey=' + inputData.hapiKey )
.then(function(res) {
return res.json();
})
.then(function(body) {
var contacts = [];
body.contacts.forEach(function(contact) {
contact.identities.forEach(function(identity) {
identity.identity.forEach(function(i) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (re.test(i.value)) {
contacts.push(i.value);
}
});
});
});
var output = {id: inputData.companyId, contacts: contacts};
callback(null, output);
})
.catch(callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment