Skip to content

Instantly share code, notes, and snippets.

@jackcoldrick90
Created April 26, 2022 08:27
Show Gist options
  • Save jackcoldrick90/9fbd04389ac9751d7ff039c354d2949b to your computer and use it in GitHub Desktop.
Save jackcoldrick90/9fbd04389ac9751d7ff039c354d2949b to your computer and use it in GitHub Desktop.
Can be used to gain a reference to the associated line item names of a deal in HubSpot
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
let lineItemNames = [];
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
hubspotClient.crm.deals.associationsApi.getAll(event.object.objectId, "line_item").then((results) => {
let lineItemPromises = results.body.results.map(item => {
return hubspotClient.crm.lineItems.basicApi.getById(item.id, ['name']).then(results => {
return results.body
})
})
Promise.all(lineItemPromises).then(resultsArray => {
console.log(resultsArray);
resultsArray.filter(item => {
console.log(item.properties.name);
lineItemNames.push(item.properties.name);
});
callback({
outputFields: {
products: lineItemNames.join(",")
}
})
})
}).catch((err) => {
console.error(err);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment