I'm using the XeroOAuth-PHP SDK and looking to download Invoices for a private application - so far so good in authenticating and downloading the first batch of 100 invoices.
I'm now looking to extend the code to include pagination to download groups of 100 invoices at a time - I can get the count of invoices for each request using:
$totalInvoices = count($invoices->Invoices[0]);
but not sure how to add a loop to start at page 1 and continue until the count of invoices is less than 100?
Here's the request that gets the first 100 Accounts Receivable invoices:
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', 'core'), array('where' => 'Type=="ACCREC"'));
I'm looking for something along these lines:
// set pagiation to page 1
$page = 1;
// start a loop for the $page counter
// download first page of invoices (first 100) - not sure how to specify page 1 here
$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', 'core'), array('where' => 'Type=="ACCREC"', 'page' => $page ));
if ($XeroOAuth->response['code'] == 200) {
// Get total found invoices
$totalInvoices = count($invoices->Invoices[0]);
// Parse Invoices
$invoices = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
// Loop through each invoice
$recnum = 1;
foreach($invoices as $invoice){
// Do Stuff
pr($invoices->Invoices[$recnum]->Invoice);
$recnum++;
}
} else {
outputError($XeroOAuth);
}
// Exit once $totalInvoices < 100
$page++;