I’m trying to pull all contacts from a specific HubSpot list through their API, but I keep hitting a wall. The API only gives me 250 contacts at most, even though my list has way more entries.
I tried using the ‘vidOffset’ parameter to get the next batch of results, but it’s not working as expected. My goal is to sync all contacts from HubSpot into my local database.
Here’s the PHP code I’m working with:
function fetchData($requestType, $endpoint, $params){
$ch = curl_init();
$endpoint = $endpoint+'&property=lastname&property=phone&limit=10&offset=5';
switch ($requestType){
case "POST":
curl_setopt($ch, CURLOPT_POST, 1);
if ($params)
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
break;
case "PUT":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
if ($params)
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
break;
default:
if ($params)
$endpoint = sprintf("%s?%s", $endpoint, http_build_query($params));
}
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$response = curl_exec($ch);
if(!$response){die("Request Failed");}
curl_close($ch);
return $response;
}
// execute the request
fetchData('GET', 'https://api.hubapi.com/contacts/v1/lists/25/contacts/all?hapikey=[YOUR_KEY]', false);
Am I missing something in my approach? Has anyone found a reliable method to extract all contacts using PHP or WordPress integration?