APIs & Integrations

manishn
Participant

Get all the contacts from HubSpot list

SOLVE

Hello,

 

Note: I want to export all the contacts from the Hubspot List to my local database using API

@IsaacTakushi @JasminLin 

I am using the contact API but it returns maximum 250 contacts only. I used 'vidOffset' parameter but no luck.

 

Here is my code with php curl.

function callAPI($method, $url, $data){
	   $curl = curl_init();
	   $url = $url.'&property=firstname&property=email&count=5&vidOffset=2';
		switch ($method){
		  case "POST":
			 curl_setopt($curl, CURLOPT_POST, 1);
			 if ($data)
				curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
			 break;
		  case "PUT":
			 curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
			 if ($data)
				curl_setopt($curl, CURLOPT_POSTFIELDS, $data);			 					
			 break;
		  default:
			 if ($data)
				$url = sprintf("%s?%s", $url, http_build_query($data));
	   }
	   // OPTIONS:
	   curl_setopt($curl, CURLOPT_URL, $url);
	   curl_setopt($curl, CURLOPT_HTTPHEADER, array(
		  'Content-Type: application/json',
	   ));
	   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	   curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

	   // EXECUTE:
	   $result = curl_exec($curl);
	   if(!$result){die("Connection Failure");}
	   curl_close($curl);
	   return $result;
	}

// call the function
callAPI('GET', 'https://api.hubapi.com/contacts/v1/lists/11/contacts/all?hapikey=[API key]', false);

Is there anything wrong I am doing? or if there is a better way to get all contact using php/wordpress then please share your experience.

 

Thanks

0 Upvotes
1 Accepted solution
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Get all the contacts from HubSpot list

SOLVE

Welcome, @manishn.

 

Happy to clarify.

 

It looks like your PHP will only make one GET request to https://api.hubapi.com/contacts/v1/lists/11/contacts/all?hapikey=your_key&property=firstname&propert....

 

This will only return five contacts since the count=5.

 

If you wish to retrieve all contacts from list 11, you must configure your code to make multiple requests to the endpoint, getting up to 100 contact records each time withcount=100.

 

At the end of each response, you will see something like:

"has-more": true,
"vid-offset": 123456

If has-more is true, then place the vid-offset value in the request URL (e.g. vidOffset=123456). Then, make another request to get the next 100 contacts. Repeat until has-more is false.

Isaac Takushi

Associate Certification Manager

View solution in original post

0 Upvotes
2 Replies 2
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Get all the contacts from HubSpot list

SOLVE

Welcome, @manishn.

 

Happy to clarify.

 

It looks like your PHP will only make one GET request to https://api.hubapi.com/contacts/v1/lists/11/contacts/all?hapikey=your_key&property=firstname&propert....

 

This will only return five contacts since the count=5.

 

If you wish to retrieve all contacts from list 11, you must configure your code to make multiple requests to the endpoint, getting up to 100 contact records each time withcount=100.

 

At the end of each response, you will see something like:

"has-more": true,
"vid-offset": 123456

If has-more is true, then place the vid-offset value in the request URL (e.g. vidOffset=123456). Then, make another request to get the next 100 contacts. Repeat until has-more is false.

Isaac Takushi

Associate Certification Manager
0 Upvotes
manishn
Participant

Get all the contacts from HubSpot list

SOLVE

Thanks, @IsaacTakushi it helps me a lot.