Skip to content

Instantly share code, notes, and snippets.

@NickDeckerDevs
Created September 24, 2022 01:21
Show Gist options
  • Save NickDeckerDevs/cac3d706c59f1f0900f765d36ba970c7 to your computer and use it in GitHub Desktop.
Save NickDeckerDevs/cac3d706c59f1f0900f765d36ba970c7 to your computer and use it in GitHub Desktop.
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
// not sure what you are doing here but putting this in a function seems better to me then the pasta
const handleQuote = (quoteObject) => {
// insert my cool code here that does stuff
}
// you should convert this to private app see: https://deckerdevs.com/blogs/hubspot-api-integrations-faqs-sunsetting-api-keys-for-private-apps
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
try {
//get quote associations
const apiResponse = await hubspotClient.crm.deals.associationsApi.getAll(event.object.objectId, 'quote')
const quoteIds = apiResponse.body.results.map(quote => quote.id)
// using for of because async call in loop
for(const id of quoteIds) {
// you might need to add more properties here to do things with this, but who knows, I don't have context
const statusResponse = await hubspotClient.crm.quotes.basicApi.getById(id, ['hs_status'])
const approvalStatus = statusResponse.body.properties.hs_status
if( approvalStatus && approvalStatus != 'DRAFT' ) {
// not sure what you are doing, but maybe send over the whole object you return from the call?
handleQuote(statusResponse.body)
}
}
} catch (err) {
console.error(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment