Created
July 19, 2017 14:22
-
-
Save li0nel/3774a96e61da93a30a00285460f8c014 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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