1

私は XeroOAuth-PHP SDK を使用しており、プライベート アプリケーション用の請求書をダウンロードしようとしています。これまでのところ、100 件の請求書の最初のバッチを認証してダウンロードするのに適しています。

一度に 100 件の請求書のグループをダウンロードするためのページネーションを含めるようにコードを拡張しようとしています。

$totalInvoices = count($invoices->Invoices[0]);

しかし、ループを追加してページ 1 から開始し、請求書の数が 100 未満になるまで続行する方法がわかりませんか?

最初の 100 件の売掛金請求書を取得する要求は次のとおりです。

$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoices', 'core'), array('where' => 'Type=="ACCREC"'));

私はこれらの線に沿って何かを探しています:

// 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++;         
4

1 に答える 1