Created
May 5, 2022 13:25
-
-
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
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) => { | |
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 | |
} | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would you use a privateApp to authenticate now that API keys have been sunsetted?
Thanks
Mark