I’m new to the API and using a modified version of the quickstart app from GitHub. I’m trying to find a contact by his email address and no matter what I try I get:
{"total":0,"results":[]}
I simplified it to search for a literal firstname and still no results. I see other people successfully searching, but all the answers are using curl rather than the library and using the API key rather than OAuth. I have OAuth working to get a token. I also have separately used curl with a v1 endpoint to successfully find a contact. But no luck with Nodejs api library and OAuth.
Here is my function doing the search:
const getContactByEmail = async (accessToken, email_address) => {
console.log('');
console.log('=== Retrieving a contact by email from HubSpot using the access token ===');
const filter = { propertyName: 'firstname', operator: 'EQ', value: 'Brian' }
const filterGroup = { filters: [filter] }
const sort = 'firstname'
const query = 'test'
const properties = ['company', 'email', 'firstname', 'lastname']
const limit = 100
const after = 0
const publicObjectSearchRequest = {
filterGroups: [filterGroup],
sorts: [sort],
query,
properties,
limit,
after
};
console.log(publicObjectSearchRequest)
console.log(publicObjectSearchRequest.filterGroups[0].filters[0])
const result = await hubspotClient.crm.contacts.searchApi.doSearch(publicObjectSearchRequest)
console.log(JSON.stringify(result.body))
return result.body
}
And here is the console output:
=== Retrieving a contact by email from HubSpot using the access token ===
{
filterGroups: [ { filters: [Array] } ],
sorts: [ 'firstname' ],
query: 'test',
properties: [ 'company', 'email', 'firstname', 'lastname' ],
limit: 100,
after: 0
}
{ propertyName: 'firstname', operator: 'EQ', value: 'Brian' }
{"total":0,"results":[]}
I tried the email_address parameter first. I also tried LTE and CONTAINS_TOKEN and other attempts all with the same result.
Please let me know what I’m missing.
Thanks
Phil