Get all companies API endpoint with offset

companies

#1

I am trying to page through the entire list of companies in my portal so that I can allow users to search for companies (since Hubspot doesn’t expose the API endpoint that they use in the sales portal to do so). Unfortunately, I can’t get the offset parameter to work.

I originally was setting the offset myself. In my first loop my offset was 0, then, if the results matched my limit (250, the Hubspot set maximum page size), I would increment my offset by the limit and request again. When I perform a request to /companies/v2/companies/paged with an offset of 0 and with an offset of 250, I get the same results!

I then noticed that in the documentation it says “If there are more records in your portal than the limit= parameter, you will need to use the offset returned in the first request to get the next set of results.”

I then, in my loop, set the offset equal to the offset that was returned to me, and this still did not work! Plus, the offset that is returned to me from the request always remains the same.

I’m guessing there is something that I am doing terribly wrong.

Here is an example of my request url"
https://api.hubapi.com/companies/v2/companies/paged?hapikey=example&properties=name&limit=250&offset=OFFSET


#2

I’ve figured it out. I was formatting the offset incorrectly. Everything is working properly now. User error.

For anyone using golang for this, the offset is a float64 that must be parsed as strconv.FormatFloat(offset, ‘f’, -1, 64).


#3

@WebWanderer Thanks for the update.

Out of curiosity what language were you using? I’m curious to know what issues we might run into down the road for parsing certain fields and for future readers of the forum.


#4

@pmanca I am using Golang for my application.

I doubt the language matters here. It was more stupidity on my part…

Simply said, you need to format your floats with the finest precision in order to ensure that you will be returning the same value that you are receiving.

The strconv.FormatFloat method accepts four parameters: the float, the format, the precision, and the bit size. The two fields to note are the format and the precision, which is where my error was.

The format f will return as many digits as possible, while the precision -1 will return as few digits as necessary to return the float exactly. This is well explained in this Stack Overflow answer.

Because our offset is being returned in the response JSON as a float64 and because we want to retrieve it exactly, we should use strconv.FormatFloat(offset, 'f', -1, 64) to properly format the float.


#5

Perfect, thanks for the clarification