⚙ Operations Hub

ToddSutt
Member

Good resource for writing programmable automation in workflows?

Hi, my company just upgraded to Operations Hub Pro for programmable automation. Generically, I would really like a resource where I can look up what functions are available to me in the @hubspot/api-client npm library. In node docs, they have some examples but also just link to the generic hubspot api docs: https://developers.hubspot.com/docs/api/overview

 

The specific thing I'm trying to figure out, is how to search through a custom object and find one that matches the "name" property. I understand how I could do this for contacts, deals, or companies, but not for my "brands" custom object.

 

Does anybody know of a good resource for seeing all available functions for hubspotClient (shown below)? Secondarily, is there a better environment for writing code for Custom Code actions in workflows that maybe has autocompletion?

 

const hubspotClient = new hubspot.Client({
    apiKey: process.env.HAPIKEY
});

hubspotClient.crm.customObject.search(searchParams) <- Something like this

0 Upvotes
1 Reply 1
Fahadwaseem
Member

Good resource for writing programmable automation in workflows?

For searching through a custom object like "brands", you can utilize the searchApi function from the crm.objects module of the HubSpot API. This function allows you to provide a set of search parameters and retrieve custom objects that match these criteria directly, without needing to retrieve all objects and filter them afterwards.
 
A generic example would look something like this:
 
 
async function searchCustomObjects() {
const hubspot = require('@hubspot/api-client');
 
const hubspotClient = new hubspot.Client({
accessToken: 'YOUR_API_KEY'
});
 
const objectType = "Custom_Object_Internal_Name";
const searchParams = {
filterGroups: [{
filters: [{
value: 'Test 1',
propertyName: 'Custom_Object_Property',
operator: 'EQ'
}]
}],
sorts: [],
properties: ['brand_name'],
limit: 10,
after: 0
};
 
try {
const apiResponse = await hubspotClient.crm.objects.searchApi.doSearch(objectType, searchParams);
console.log(apiResponse.results);
} catch (e) {
console.error(e);
}
}
 
searchCustomObjects();