Created
September 15, 2022 23:10
-
-
Save HubSpotHanevold/3f51e01ca21fac05474f40f825b4d6cc to your computer and use it in GitHub Desktop.
search crm for custom object for custom coded actions
This file contains hidden or 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) => { | |
// 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