x

Pagination issue with Square API

Good evening everyone,

 

I've been pulling my hair out for the past two evenings on an issue with the Square API and I'm sincerely hoping that someone here might be able to steer me in the correct direction ...

 

I am using Square Connect V2 for PHP and I'm attempting to build a pull down list of all of our customers.  I am able to retrieve the first 100 of our ~450 customers, but not the rest.  I read about getCursor() and attempted to implement it, but with no luck.

 

After the first

$customer_api->listCustomers($authorization)->getCustomers();

I issue 

$customer_api->listCustomers($authorization)->getCursor();

 

Then I parse through the first 100 and start the select statement.  I capture the cursor and logged it after each iteration.  Then if cusor has content I issue the following

$customer_api->listCustomers($authorization, $cursor)->getCustomers();

 

Followed by another

$customer_api->listCustomers($authorization)->getCursor();

 

But the value of cursor is exactly the same as it was the previous iteration.  Can anyone please offer any suggestions?  I'm dead in the water.  I am most gratious for any assistance.

 

Martin

Tags (1)
1,099 Views
Message 1 of 2
Report
1 REPLY 1
Alumni

Notice how your second and fourth codes are the same? that is why they return the same result. You'd probably rather do something like: 

$customers = [];
$firstPage = $customer_api->listCustomers($authorization);
$customers = array_merge($customers, $firstpage->getCustomers();
$secondPage =  $customer_api->listCustomers($authorization,$firstPage->getCursor());
...

Stick that in a while loop and you should have a pretty good way to get all of your customers. Everytime you call 

$customer_api->listCustomers($authorization);

You are making another request to the server, so you probably want to store the results instead of requesting over and over. 

1,089 Views
Message 2 of 2
Report