Multiple times I’ve tried to use the http service in an automation script, and I’ve never been able to get past unresolved promise error.
My script is just trying to create a lead in a outreach automation tool when the entity meets a certain criteria inside of Fibery.
Can someone help me debug this issue?
const http = context.getService('http');
const fibery = context.getService('fibery');
async function main() {
// Extract necessary data from the triggering entity
for (let i = 0; i < args.currentEntities.length; i++) {
const companyEntity = await fibery.getEntityById('CRM/Companies', args.currentEntities[i]['Companies 1'], ['Name', 'Website']);
const triggerEntity = args.currentEntities[i];
const companyName = companyEntity['Name'];
const companyWebsite = companyEntity['Website']
const linkedinUrl = triggerEntity['Linkedin'];
const x = triggerEntity['X'];
console.log(companyEntity + ': ' + companyName);
console.log(companyEntity + ': ' + companyWebsite);
console.log(`${linkedinUrl}, ${x}`);
//Prepare data for the LaGrowthMachine API request
const lagrowthmachineData = {
audience: 'VSAAS',
companyName: companyName || '',
companyUrl: companyWebsite || '',
linkedinUrl: linkedinUrl,
twitter: x,
// Add more fields as necessary
};
// Make POST request to LaGrowthMachine API
try {
const response = await http.postAsync('https://apiv2.lagrowthmachine.com/flow/leads?apikey=Your-external-apikey', {
body: lagrowthmachineData,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
console.log('Lead added to LaGrowthMachine successfully:', response);
} catch (error) {
console.error('Error adding lead to LaGrowthMachine:', error);
}
}
};
main();