Pagination

Last updated 02/19/2021

This document outlines the use of the paging tokens returned by various parts of the Zentail Open API. Some example calls that utilize pagination include:

The Zentail API uses paging to reduce the response time as well as control the resources used in each transaction. For calls that are paged, you will see the pagination object on the result specification.

json
{ "results": [], // An array of result objects, structure depends on the particular endpoint. "pagination": { "hasNext": <boolean> // Either true if there is a next page, or false if this is the last page. "nextToken": "<url>" // The full url that include the next token. } }

This object will dictate how to proceed:

  1. Check the pagination object for the key hasNext. If it is false, there are no more pages and you are at the end of the list. If it's true, proceed to step 2.
  2. Take the value of pagination.nextToken and make a request to that URL. The value will contain the full URL so do not append it to the request, just send a GET request to that URL.
  3. Repeat step 2 until hasNext is false

See the following example PHP code which makes calls to our api to list all orders:

php
<?php use GuzzleHttp\Client; function listAllOrdersToken(string $url) { $client = new Client(["base_uri" => $url]); $response = $client->request("GET", "", [ "headers" => ["AUTHORIZATION" => "1e89c5e609fee7182ef8d5cbefe69a2caf7c082329c381b252f08c83aedbf545"] ]); $results = json_decode($response->getBody()); foreach($results->results as $order) { yield $order; } if($results->pagination->hasNext) { yield from listAllOrdersToken($results->pagination->nextToken); } } function listAllOrdersSince(int $timestamp) { $client = new Client(["base_uri" => "https://api.zentail.com/"]); $response = $client->request("GET", "/v1/salesOrder?lastUpdatedTs=" . urlencode(date("c", $timestamp)), [ "headers" => ["AUTHORIZATION" => "1e89c5e609fee7182ef8d5cbefe69a2caf7c082329c381b252f08c83aedbf545"] ]); $results = json_decode($response->getBody()); foreach($results->results as $order) { yield $order; } if($results->pagination->hasNext) { yield from listAllOrdersToken($results->pagination->nextToken); } } foreach(listAllOrdersSince(strtotime("-60 days")) as $order) { echo $order->orderNumber . " -- " . $order->lastUpdatedTs . " \n"; }
Was this section helpful?
Yes No