I wanted to search for a custom object that I've created and wanted to use the API in a custom code workflow. The documentation states that you have to use the following:
I've run into this rather frustrating problem in the past as well. You're absolutely correct, the documentation is outdated. Also, there's a cool method you can use to check out the object structure of the hubspot API client whenever you're in doubt, but just using console.log() to print out that hierarchy. They seem to have done some restructuring. Take the below, for example:
const hubspot = require("@hubspot/api-client");
exports.main = async (event, callback) => {
/*****
How to use secrets
Secrets are a way for you to save API keys and set them as a variable to use anywhere in your code
Each secret needs to be defined like the example below
*****/
const hubspotClient = new hubspot.Client({
apiKey: process.env.API_KEY
});
try {
console.log(hubspotClient.crm.objects)
} catch (err) {
console.error(err);
// We will automatically retry when the code fails because of a rate limiting error from the HubSpot API.
throw err;
}
};
which produced the following output:
All that being said, I think any method that gets you the result you're looking for in cases like these, should be considered a viable and acceptable solution, so I'd say full speed ahead with what you've come up with. Going forward, if you ever run into a similar issue, I recommend logging the client's structure so you know exactly what you're working with and what your options are.
I've run into this rather frustrating problem in the past as well. You're absolutely correct, the documentation is outdated. Also, there's a cool method you can use to check out the object structure of the hubspot API client whenever you're in doubt, but just using console.log() to print out that hierarchy. They seem to have done some restructuring. Take the below, for example:
const hubspot = require("@hubspot/api-client");
exports.main = async (event, callback) => {
/*****
How to use secrets
Secrets are a way for you to save API keys and set them as a variable to use anywhere in your code
Each secret needs to be defined like the example below
*****/
const hubspotClient = new hubspot.Client({
apiKey: process.env.API_KEY
});
try {
console.log(hubspotClient.crm.objects)
} catch (err) {
console.error(err);
// We will automatically retry when the code fails because of a rate limiting error from the HubSpot API.
throw err;
}
};
which produced the following output:
All that being said, I think any method that gets you the result you're looking for in cases like these, should be considered a viable and acceptable solution, so I'd say full speed ahead with what you've come up with. Going forward, if you ever run into a similar issue, I recommend logging the client's structure so you know exactly what you're working with and what your options are.