Created
April 26, 2022 08:27
-
-
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
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
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