Invoke an external GET API and store the data retrieved from API in HubSpot HubDB
SOLVE
Hello, I'm a newbie to HubSpot and need to implement a usecase wherein I need to pull some data from a third party API in HubSpot and store the same in the HubDB in some custom table.
Any leads on how this can be done would be really helpful to start with.
I was able to locate the documentation of migrating to private app and tried out the approach suggested in there. I was able to get the Custom Code action working with the Access token instead of API KEY.
Pre-requisite: Create a private app with your deveopers HubSpot account
1. Go to Settings --> Integrations --> Private Apps
2. Create Private App
3. Provide the name to the App
4. Add the modules (for ex., hubdb, contacts, deals, etc.) as required
5. Create app
6. You should be able to find your access token in the app which you can add as Secret in Custom Code Action instead of API KEY
Here is the final code snippet which could help someone else as well:
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
const hubspotClient = new hubspot.Client({ accessToken: process.env.ACCESSTOKEN });
// Make sure ACCESSTOKEN is added in SecretKey
const values = {
"id":"3", "userid": "16", "title": "Test new row", "completed": "true", };
This might be a bug with the HubSpot NodeJS library or a mistake in the docs, cause if I check the example of the docs, your code should be correct.
However, the error indicates that hubspotClient.cms.hubdb.rows is undefined, which is odd, cause this is the same in the docs. But if I check the github, I think it should be: hubspotClient.cms.hubdb.rowsApi.createTableRow(tableIdOrName, HubDbTableRowV3Request);
Learn more about HubSpot by following me on LinkedIn or YouTube
✅ Did my answer solve your issue? Help the community by marking it as the solution.
I was able to locate the documentation of migrating to private app and tried out the approach suggested in there. I was able to get the Custom Code action working with the Access token instead of API KEY.
Pre-requisite: Create a private app with your deveopers HubSpot account
1. Go to Settings --> Integrations --> Private Apps
2. Create Private App
3. Provide the name to the App
4. Add the modules (for ex., hubdb, contacts, deals, etc.) as required
5. Create app
6. You should be able to find your access token in the app which you can add as Secret in Custom Code Action instead of API KEY
Here is the final code snippet which could help someone else as well:
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
const hubspotClient = new hubspot.Client({ accessToken: process.env.ACCESSTOKEN });
// Make sure ACCESSTOKEN is added in SecretKey
const values = {
"id":"3", "userid": "16", "title": "Test new row", "completed": "true", };
I cannot speak to the third party data and how you will retrieve it, but on the HubSpot side, you will need to create a HubDB table and then update the table with your data. The information on the HubDB API is available here
@miljkovicmisa might be able to assist with more if you provide more details about the setup 😀
2022-07-13T11:12:03.646Z ERROR TypeError: Cannot read property 'rowsApi' of undefined
at Object.exports.main (/var/task/file.js:20:58)
at Runtime.exports.hubspot_handler [as handler] (/var/task/hubspotHandler.js:6:21)
at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)
Please let me know your thoughts on the approach and resolution to the issue I'm facing while storing data to HubDb.
Any leads on this would be helpful to move ahead! 🙂