Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HubSpotHanevold/3f51e01ca21fac05474f40f825b4d6cc to your computer and use it in GitHub Desktop.
Save HubSpotHanevold/3f51e01ca21fac05474f40f825b4d6cc to your computer and use it in GitHub Desktop.
search crm for custom object for custom coded actions
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
// Instantiate a new HubSpot API client using the HAPI key (secret)
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
// Create search criteria
const filter = {
propertyName: 'name',
operator: 'EQ',
value: 'Volvo XC40'
}
const filterGroup = {
filters: [filter]
}
const sort = JSON.stringify({
propertyName: 'name',
direction: 'DESCENDING'
})
const properties = ['name']
const limit = 1
const after = 0
const searchCriteria = {
filterGroups: [filterGroup],
sorts: [sort],
properties,
limit,
after
}
const objectType = 'car'
const result = await hubspotClient.crm.objects.searchApi.search(objectType, searchCriteria);
const make_json = JSON.stringify(result);
const obj = JSON.parse(make_json)
let returned_id = obj.response.body.results[0].id;
console.log(JSON.stringify(obj))
console.log(returned_id)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment