Hubspot API: Getting all contacts (100+)
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.
I've found an older topic on this but this uses an external repo. I've found a newer repo, but can't get that one to work. Best case, I don't use an external lib because I need such a small piece of code.
I've tried the following code, but it keeps on loading. My guess is that the variables don't update. What am I doing wrong?
<?php
echo '<pre>';
function getData($offset = 0)
$properties = "&property=email&property=firstname&property=funnel&property=hs_lead_status&property=start_session";
$apikey = "xxxx-xx-xx";
$feed_url = "https://api.hubapi.com/contacts/v1/lists/all/contacts/recent?hapikey=". $apikey. $properties.'&vidOffset='.$offset;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $feed_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$data = json_decode($response);
return $data; //return the results for use
$allData = array();
$offset = 0;
$hasMore = true;
while ($hasMore === true)
$response = getData( $offset );
$allData = $response;
$offset = $response->'vid-offset';
$hasMore = $response->'has-more';
var_dump( $hasMore );
$hasMore = false;
api loops while-loop hubspot
add a comment |
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.
I've found an older topic on this but this uses an external repo. I've found a newer repo, but can't get that one to work. Best case, I don't use an external lib because I need such a small piece of code.
I've tried the following code, but it keeps on loading. My guess is that the variables don't update. What am I doing wrong?
<?php
echo '<pre>';
function getData($offset = 0)
$properties = "&property=email&property=firstname&property=funnel&property=hs_lead_status&property=start_session";
$apikey = "xxxx-xx-xx";
$feed_url = "https://api.hubapi.com/contacts/v1/lists/all/contacts/recent?hapikey=". $apikey. $properties.'&vidOffset='.$offset;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $feed_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$data = json_decode($response);
return $data; //return the results for use
$allData = array();
$offset = 0;
$hasMore = true;
while ($hasMore === true)
$response = getData( $offset );
$allData = $response;
$offset = $response->'vid-offset';
$hasMore = $response->'has-more';
var_dump( $hasMore );
$hasMore = false;
api loops while-loop hubspot
add a comment |
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.
I've found an older topic on this but this uses an external repo. I've found a newer repo, but can't get that one to work. Best case, I don't use an external lib because I need such a small piece of code.
I've tried the following code, but it keeps on loading. My guess is that the variables don't update. What am I doing wrong?
<?php
echo '<pre>';
function getData($offset = 0)
$properties = "&property=email&property=firstname&property=funnel&property=hs_lead_status&property=start_session";
$apikey = "xxxx-xx-xx";
$feed_url = "https://api.hubapi.com/contacts/v1/lists/all/contacts/recent?hapikey=". $apikey. $properties.'&vidOffset='.$offset;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $feed_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$data = json_decode($response);
return $data; //return the results for use
$allData = array();
$offset = 0;
$hasMore = true;
while ($hasMore === true)
$response = getData( $offset );
$allData = $response;
$offset = $response->'vid-offset';
$hasMore = $response->'has-more';
var_dump( $hasMore );
$hasMore = false;
api loops while-loop hubspot
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.
I've found an older topic on this but this uses an external repo. I've found a newer repo, but can't get that one to work. Best case, I don't use an external lib because I need such a small piece of code.
I've tried the following code, but it keeps on loading. My guess is that the variables don't update. What am I doing wrong?
<?php
echo '<pre>';
function getData($offset = 0)
$properties = "&property=email&property=firstname&property=funnel&property=hs_lead_status&property=start_session";
$apikey = "xxxx-xx-xx";
$feed_url = "https://api.hubapi.com/contacts/v1/lists/all/contacts/recent?hapikey=". $apikey. $properties.'&vidOffset='.$offset;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $feed_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$data = json_decode($response);
return $data; //return the results for use
$allData = array();
$offset = 0;
$hasMore = true;
while ($hasMore === true)
$response = getData( $offset );
$allData = $response;
$offset = $response->'vid-offset';
$hasMore = $response->'has-more';
var_dump( $hasMore );
$hasMore = false;
api loops while-loop hubspot
api loops while-loop hubspot
asked Nov 13 '18 at 10:45
IljaIlja
62
62
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
One thing that I can think of is that your loop doesn't take into consideration the fact that HubSpot only allows 10 request per second (see here) - your loop might be exceeding that and as such causing the issues. You should add the following code just before the end of your while loop (this will sleep the script for 0.1 seconds):
usleep(100000);
Additionally, it might be a better and a cleaner idea to use a PHP API library such as this one.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279264%2fhubspot-api-getting-all-contacts-100%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
One thing that I can think of is that your loop doesn't take into consideration the fact that HubSpot only allows 10 request per second (see here) - your loop might be exceeding that and as such causing the issues. You should add the following code just before the end of your while loop (this will sleep the script for 0.1 seconds):
usleep(100000);
Additionally, it might be a better and a cleaner idea to use a PHP API library such as this one.
add a comment |
One thing that I can think of is that your loop doesn't take into consideration the fact that HubSpot only allows 10 request per second (see here) - your loop might be exceeding that and as such causing the issues. You should add the following code just before the end of your while loop (this will sleep the script for 0.1 seconds):
usleep(100000);
Additionally, it might be a better and a cleaner idea to use a PHP API library such as this one.
add a comment |
One thing that I can think of is that your loop doesn't take into consideration the fact that HubSpot only allows 10 request per second (see here) - your loop might be exceeding that and as such causing the issues. You should add the following code just before the end of your while loop (this will sleep the script for 0.1 seconds):
usleep(100000);
Additionally, it might be a better and a cleaner idea to use a PHP API library such as this one.
One thing that I can think of is that your loop doesn't take into consideration the fact that HubSpot only allows 10 request per second (see here) - your loop might be exceeding that and as such causing the issues. You should add the following code just before the end of your while loop (this will sleep the script for 0.1 seconds):
usleep(100000);
Additionally, it might be a better and a cleaner idea to use a PHP API library such as this one.
answered Dec 7 '18 at 13:00
itoctopusitoctopus
3,34342236
3,34342236
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279264%2fhubspot-api-getting-all-contacts-100%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown