APIs & Integrations

PCarlson
参加者

Search Contact using Nodejs Library Call

解決

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

0 いいね!
1件の承認済みベストアンサー
RMones
解決策
投稿者 | Platinum Partner
投稿者 | Platinum Partner

Search Contact using Nodejs Library Call

解決

I'm using the same api call, with only the filterGroup set. 
This is working perfect! 

If you remove the 

sorts, query, properties, limit, after

 

From your publicObjectSearchRequest, is the call then working?

元の投稿で解決策を見る

3件の返信
PCarlson
参加者

Search Contact using Nodejs Library Call

解決

Thanks RMones, that worked! I gave you an upvote and I'll accept your post as solution.

 

Any additional info on why I cannot have the other options and why it does not work with all options (I took this straight from the GitHub sample and only modified the filter)?

 

I'll experiment and see which breaks it, but any tips on what's going on, what combinations work and what doesn't work are very welcome!

0 いいね!
PCarlson
参加者

Search Contact using Nodejs Library Call

解決

The offending line was

const query = 'test'

Removing from publicObjectSearchRequest only the single line like:

query,

 made the error go away, but it did not list the properties I requested, so I'll have to play some more.

 

FYI, that line was exactly taken from the README.md under "{EXAMPLE} Search Contacts:" at https://github.com/HubSpot/hubspot-api-nodejs so it would be nice to fix that so that example works.

 

Phil

0 いいね!
RMones
解決策
投稿者 | Platinum Partner
投稿者 | Platinum Partner

Search Contact using Nodejs Library Call

解決

I'm using the same api call, with only the filterGroup set. 
This is working perfect! 

If you remove the 

sorts, query, properties, limit, after

 

From your publicObjectSearchRequest, is the call then working?