Skip to content

Instantly share code, notes, and snippets.

@jackcoldrick90
Created May 5, 2022 13:25
Show Gist options
  • Save jackcoldrick90/af68bb91b0807342be6d74bc095ffc47 to your computer and use it in GitHub Desktop.
Save jackcoldrick90/af68bb91b0807342be6d74bc095ffc47 to your computer and use it in GitHub Desktop.
This snippet queries a HubDB table. The table in this instance contains various product related resources. You can use the information returned to copy into properties on the contact record and personalise an email or segment via list for smart content
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
const product_of_interest = event.inputFields['product_of_interest'];
let resourceName, resourceLink, resourceDescription, resourceImage;
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
hubspotClient
.apiRequest({
method: 'GET',
path: '/cms/v3/hubdb/tables/4664254/rows?resource_type=' + encodeURIComponent(product_of_interest),
body: {}
})
.then(searchResult => {
resourceName = searchResult.body.results[0].values.resource_name;
resourceDescription = searchResult.body.results[0].values.resource_description;
resourceLink = searchResult.body.results[0].values.resource_link;
resourceImage = searchResult.body.results[0].values.resource_image.url;
callback({
outputFields: {
resourceName: resourceName,
resourceLink: resourceLink,
resourceDescription: resourceDescription,
resourceImage: resourceImage
}
})
})
}
@likwid23
Copy link

How would you use a privateApp to authenticate now that API keys have been sunsetted?
Thanks
Mark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment