APIs & Integrations

AGuardeño
Participante

API v3 (@hubspot/api-client) Companies doSearch method doesn't filter with property name in Node

In my company, we now have the need to filter companies by name in the HubSpot API.

I looked at the documentation and found the doSearch endpoint in companies: https://developers.hubspot.com/docs/api/crm/companies 

 

I used that page to create the object to filter by name and tried it in Postman with a test company we have (so it already exists and should return a non-empty result). However, it doesn't return anything.

 

Slack_dmqoDjCze4.png

 

If I do a getAll from companies and later filter it by the name property, I can find the company with its properties. But this method isn't a good solution since it can take around 30 seconds to execute and return all the companies.

So... Am I doing something wrong in the object that I have to pass as a filter, or this method doesn't work with the property name?

0 Me gusta
5 Respuestas 5
webdew
Guía | Partner nivel Diamond
Guía | Partner nivel Diamond

API v3 (@hubspot/api-client) Companies doSearch method doesn't filter with property name in Node

Hi @AGuardeño ,

Hope this works for you and make sure property and value exist in hubspot companies.

<?php
$data = '{
"filterGroups":[
{
"filters":[
{
"propertyName": "<property-Key>",
"operator": "EQ",
"value": "<property-Value>"
}
]
}
]
}';
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.hubapi.com/crm/v3/objects/companies/search?hapikey=YOUR_HUBSPOT_API_KEY');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);


Hope this helps!


If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards. 

0 Me gusta
AGuardeño
Participante

API v3 (@hubspot/api-client) Companies doSearch method doesn't filter with property name in Node

Hello @webdew

Thanks for your reply but as I said in my previous reply, my issue is that I need the object as I posted in my screenshot of Postman for calling the HubSpot API through Node with the method hubspotClient.crm.companies.searchApi.doSearch(publicObjectSearchRequest) as it says in the official documentation, which is falling to function as it should be.

Calling it from curl with an object with another format is of no use for me since I'm using a typed HubSpot API method in Typescript & Node.

Regards,
Alicia

0 Me gusta
dennisedson
Equipo de producto de HubSpot
Equipo de producto de HubSpot

API v3 (@hubspot/api-client) Companies doSearch method doesn't filter with property name in Node

Hey @AGuardeño 

First, you need to remove the unused components. 

If all you are doing is looking only for the name property, you don't really need a filterGroup either

This should do the trick:

{
  "filters": [
      {
          "value": "Nodeletepls_tcp",
          "propertyName": "name",
          "operator": "EQ"
      }
  ]
}
AGuardeño
Participante

API v3 (@hubspot/api-client) Companies doSearch method doesn't filter with property name in Node

Hi @dennisedson thanks for your answer, it works in Postman now.

 

But I want to use it in Node with the following method: 
hubspotClient.crm.companies.searchApi.doSearch(objectToFilterCompaniesByName)

And what you have given me, doesn't work in Typescript & Node because is asking for an object with the same syntax that I have written in my first screenshot.

Any ideas on how to make this work in Node? 

Shay_B
Colaborador

API v3 (@hubspot/api-client) Companies doSearch method doesn't filter with property name in Node

Old case, but did you resolve this? Running against a similar problem with hubspotClient.crm.companies.searchApi.doSearch; it;s just bringing me all my companies by creation date, completely ignoring the search string.

0 Me gusta