APIs & Integrations

Kumarp1
Participant

Increase the limit parameter in Get all companies

SOLVE

I have more than 6000 companies in HubSpot and i want to get all companies while hitting the Get all companies API. Currently i can get Max 250 companies at a time. Please suggest me how can i manage such kind of situation.

0 Upvotes
2 Accepted solutions
WendyGoh
Solution
HubSpot Employee
HubSpot Employee

Increase the limit parameter in Get all companies

SOLVE

Hi @Kumarp1,

 

I hope all is well with you 😄

 

When looking to get all companies using this endpoint here: Get all companies there is a maximum value of 250 return limit. The reason behind having a limit is because there may be portals with significant number of contacts and returning all of them in a single request would result in timeouts and/or huge response sizes.

 

That said, your team can look into using a if statement to gather all the companies records. If the has-more value is true, it means that there's another page of company records and for that you can use the offset value to get to the next page.

 

E.g.:

https://api.hubspot.com/companies/v2/companies/paged?portalId={{portal_id}}&offset=2100755540

Hope this helps to clarify!

View solution in original post

Kumarp1
Solution
Participant

Increase the limit parameter in Get all companies

SOLVE

Hi WendyGoh

Thankyou so much for your support.

View solution in original post

0 Upvotes
6 Replies 6
WendyGoh
Solution
HubSpot Employee
HubSpot Employee

Increase the limit parameter in Get all companies

SOLVE

Hi @Kumarp1,

 

I hope all is well with you 😄

 

When looking to get all companies using this endpoint here: Get all companies there is a maximum value of 250 return limit. The reason behind having a limit is because there may be portals with significant number of contacts and returning all of them in a single request would result in timeouts and/or huge response sizes.

 

That said, your team can look into using a if statement to gather all the companies records. If the has-more value is true, it means that there's another page of company records and for that you can use the offset value to get to the next page.

 

E.g.:

https://api.hubspot.com/companies/v2/companies/paged?portalId={{portal_id}}&offset=2100755540

Hope this helps to clarify!

Kishore
Member

Increase the limit parameter in Get all companies

SOLVE

Hi WendyGoh,

 

do we have to change Offset values very time at endpoint ? Or it takes automatically?

 

i have same problem, i have 3357 companies records , incase if we have to change offsetvalue manually every time at endpoint then what is the use of API if we do manually ??

 

please help me with your reply.

0 Upvotes
WendyGoh
HubSpot Employee
HubSpot Employee

Increase the limit parameter in Get all companies

SOLVE

Hey @Kishore,

 

As mention on this documentation here:

each request will also return two values, offset and has-more. If has-more is true, you'll need to make another request, using the offset to get the next page of company records. These are often used with a recursive function in order to get all companies stored in a CRM.

For instance, if you've 300 companies in your portal and your team is looking to get all 300 companies records using the Get all companies endpoint:

1. The first API call will return a maximum number of result - 250 (if the limit is set to 250)
i.e.
GET companies/v2/companies/paged?limit=250

Assuming, the has-more is true and the offset value is 4552438489

 

2. On the second API call, you would need to include the offset value on the request url to page to the second page
i.e.
GET companies/v2/companies/paged?limit=250&offset=4552438489

 

*If on the second call, has-more is still true, you would need to grab the newly generated offset value and use it on the third call.

 

The offset value change upon each call. 

0 Upvotes
JMiljak
Member

Increase the limit parameter in Get all companies

SOLVE

Hi,

do you know how to return body data from callback function of request function : 

request(finalUrl, async (error, response, body) => { ... return JSON.parse(body)}
I know it must be something with asynchronous code, but I do not know how to return data from callback inside request function?
0 Upvotes
Kumarp1
Solution
Participant

Increase the limit parameter in Get all companies

SOLVE

Hi WendyGoh

Thankyou so much for your support.

0 Upvotes
Kishore
Member

Increase the limit parameter in Get all companies

SOLVE

Hi Kumar,

how did you achive it please help me 

i have same problem, i have 3357 companies records , incase if we have to change offsetvalue manually every time at endpoint then what is the use of API if we chnage offset manually ??

 

please help me with your reply.

0 Upvotes