APIs & Integrations

TalhaAhmed
Member

hubspot search api returning all companies instead of one

SOLVE

Hi,

 

I'm using the following code to search for a specific company in Hubspot but no matter what filters I use I get all companies instead of one:

 

const response = await axios.post('https://api.hubapi.com/crm/v3/objects/companies/search?hapikey=myapikey, {
data: {
filters: [
{
value: "Greenwood",
propertyName: "companyName",
operator: "EQ",

}
]
}
})

console.log(response.data)

 

Can someone please help me troubleshoot this?

 

Thanks

0 Upvotes
1 Accepted solution
mangelet
Solution
Guide | Platinum Partner
Guide | Platinum Partner

hubspot search api returning all companies instead of one

SOLVE

@TalhaAhmed consider removing this: data: { entirely, just use the filters i sent you... it works on my end.

Martin Angeletti
HubSpot Veteran (12+ years)

Worried about messing up your HubSpot? I've got your back.

Join the thousands of people who have discovered how to avoid problems with simple tricks and have started to dominate HubSpot (and not be dominated).

️ Don't get left behind.

→ Click the subscribe button and scroll down to find the opt-in box.

Subscribe

Did I help answer your question? Mark this as a solution.

View solution in original post

0 Upvotes
6 Replies 6
mangelet
Solution
Guide | Platinum Partner
Guide | Platinum Partner

hubspot search api returning all companies instead of one

SOLVE

@TalhaAhmed consider removing this: data: { entirely, just use the filters i sent you... it works on my end.

Martin Angeletti
HubSpot Veteran (12+ years)

Worried about messing up your HubSpot? I've got your back.

Join the thousands of people who have discovered how to avoid problems with simple tricks and have started to dominate HubSpot (and not be dominated).

️ Don't get left behind.

→ Click the subscribe button and scroll down to find the opt-in box.

Subscribe

Did I help answer your question? Mark this as a solution.

0 Upvotes
TalhaAhmed
Member

hubspot search api returning all companies instead of one

SOLVE

I've tried removing data object before but without that, I'm getting this error:

 

Executed 'Functions.createScore' (Failed, Id=f648ac53-fe3f-4793-95b5-00fbcab56b7f, Duration=957ms)
System.Private.CoreLib: Exception while executing function: Functions.createScore. System.Private.CoreLib: Result: Failure
Exception: Error: Request failed with status code 400
Stack: Error: Request failed with status code 400
at createError (D:\azure\node_modules\axios\lib\core\createError.js:16:15)
at settle (D:\azure\node_modules\axios\lib\core\settle.js:17:12)
at IncomingMessage.handleStreamEnd (D:\azure\node_modules\axios\lib\adapters\http.js:322:11)
at IncomingMessage.emit (node:events:538:35)
at endReadableNT (node:internal/streams/readable:1345:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21).

 

I'm using this code now: 

 

const response = await axios.post('https://api.hubapi.com/crm/v3/objects/companies/search?hapikey=myhapikey', {
filterGroups: [
{
filters: [
{
value: 'Greenwood',
propertyName: 'City',
operator: 'EQ'
}
]
}
],
sorts: ['City'],
properties: ['City'],
limit: 1,
after: 0
})

console.log(response.data)

 

 

0 Upvotes
mangelet
Guide | Platinum Partner
Guide | Platinum Partner

hubspot search api returning all companies instead of one

SOLVE

It seems you have changed "name" to "City". Please try "city". Capitalization is important.

The rest seems ok. 

Martin Angeletti
HubSpot Veteran (12+ years)

Worried about messing up your HubSpot? I've got your back.

Join the thousands of people who have discovered how to avoid problems with simple tricks and have started to dominate HubSpot (and not be dominated).

️ Don't get left behind.

→ Click the subscribe button and scroll down to find the opt-in box.

Subscribe

Did I help answer your question? Mark this as a solution.

0 Upvotes
TalhaAhmed
Member

hubspot search api returning all companies instead of one

SOLVE

Thanks. It worked when I changed 'City' to 'city'. Not sure why wasn't working as the original name is City with capital C. 

mangelet
Guide | Platinum Partner
Guide | Platinum Partner

hubspot search api returning all companies instead of one

SOLVE

@TalhaAhmed your filters seem off, consider trying these:

 

{
filterGroups: [
{
filters: [
{
value: "Andimol",
propertyName: "name",
operator: "EQ",
},
],
},
],
sorts: ["name"],
properties: ["name"],
limit: 1,
after: 0,
}
Martin Angeletti
HubSpot Veteran (12+ years)

Worried about messing up your HubSpot? I've got your back.

Join the thousands of people who have discovered how to avoid problems with simple tricks and have started to dominate HubSpot (and not be dominated).

️ Don't get left behind.

→ Click the subscribe button and scroll down to find the opt-in box.

Subscribe

Did I help answer your question? Mark this as a solution.

0 Upvotes
TalhaAhmed
Member

hubspot search api returning all companies instead of one

SOLVE

Still getting all companies after using your code here's the updated code:

 

const response = await axios.post('https://api.hubapi.com/crm/v3/objects/companies/search?hapikey=myhapikey, {
data: {
filterGroups: [
{
filters: [
{
value: 'Greenwood',
propertyName: 'City',
operator: 'EQ'
}
]
}
],
sorts: ['City'],
properties: ['City'],
limit: 1,
after: 0
}
})

 

console.log(response.data)

 

In the next step, I want to change this property's value but can't dot that unless I'm able to filter a company. I think this api is functioning properly.