Pagination API Contacts


#1

Hi All,

I'm trying to create one big json file with all my contacts. Since the API returns max 100 contacts I have to work with pagination. My lack in php knowledge let me in the dark of how to achieve this. Can anyone point me in the right direction here?

What I have so far:

$limit = 100;
$apikey = "xxxxx";
$feed_url = "https://api.hubapi.com/contacts/v1/lists/all/contacts/recent?hapikey=". $apikey .'&count='. $limit;
$feed_json = file_get_contents( $feed_url );
$feed_array = json_decode( $feed_json );

// Here I go on and read the data etc.

My question is: how do I go trough 300 contacts and put them into 1 array (json).

Thanks so much.

Kind,
Ilja


#3

Hi @Ilja-developer, I do not know much about pagination with PHP, but something like a while loop could work: https://www.w3schools.com/php/php_looping.asp/. You could execute a blog of code (the request) multiple times until the has-more property that gets returned is equal to false. After each loop, you can push the values into an array. I can't speak to specifics, but this is a common practice. Any PHP developers have example code that they could provide?


#4

Thanks, That could work, as do a while statement. Question is the specific since the request URL needs to be updated with the vidOffset value.

An example code would be amazing..


#5

Hi @Ilja-developer, I've found the following repo on Github you might be able to check out. I can't personally provide any example code, but know we are working on building out our examples and a possible library in the future. Here's the Github repo: https://github.com/ryanwinchester/hubspot-php


#6

Tnx.

So I did some digging and found the following: https://stackoverflow.com/questions/30983587/getting-full-list-of-contacts-from-hubspot-api/32744452.

The repo they use is: https://github.com/HubSpot/haPiHP

The code works perfectly so I guess my question is answered. Tho this raises a new question.

The repo you shared is much more recent. But I cant get the same results using that repo. How can I use the newer repo to achieve the same result..?

Thanks so much.

Ilja


#7

Did also posted it on stackoverflow


#8

Hi @Ilja-developer, I'd say the best option would be to wait for a response on stack overflow, or submit a github issue on their repo. I can't speak to why one PHP repo would work but one wouldn't as these are all external developers simply utilizing the HubSpot APIs. Perhaps their code doesn't work for every use-case?