Togai’s top-level API resources offer robust support for bulk fetching via the “list” API method. This method is applicable across various resource types including customers, accounts, event schemas, usage meters, and price plans. Regardless of the resource, these list APIs follow a common structure.

Pagination Query Parameters

  • pageSize: This parameter determines the number of results per page. Togai supports up to 100 results per page.
  • nextToken: By providing a nextToken, you can retrieve a page of objects occurring immediately after the last object from the latest list.

These list APIs accept few other query parameters to support Filtering, Searching and Sorting. Refer Filtering, searching and sorting page for more information on that topic.

Retrieving Results

The response from a list API represents a single page list of objects. If you do not input a nextToken, you will receive the first page of this stream. The result contains data which is a list of requested entity objects and nextToken

{
    "data": [
        {...},
        {...},
        ...
    ],
    "nextToken": "eyJwYXlsb2FkIjp7ImlkIjoiY3VzdG9tZXIxMjMifSwicGFnZVNpemUiOjIwLCJxdWVyeUNvbnRleHQiOnsiZmlsdGVyQnkiOltbeyJmaXJzdCI6InN0YXR1cyIsInNlY29uZCI6eyJ0eXBlIjoiRVEifX0sWyJBQ1RJVkUiXV1dLCJzb3J0QnkiOnsiaWQiOiJBU0MifSwic2VhcmNoT24iOm51bGx9LCJ0b2tlblR5cGUiOiJORVhUIn0="
}

Example Usages

Retrieving first page of results

To list customers, make a GET request to the following endpoint:

GET /customers

This request will return the first page consisting 20 of the customers along with a nextToken. If this is a last page, nextToken will be null.

At times, the last page can return a non-null nextToken. This means, you will make one extra API call to receive an empty list with a nextToken as null to ascertain that you have read all of the results.

Limiting Results

If you’d like to limit the number of results per page, you can specify a pageSize. For example, to get only 10 results per page:

GET /customers?pageSize=10

This request will return the first page of the customer list, with each page containing up to 10 customers.

Retrieving next pages

To retrieve the next page of customers, you would include the nextToken obtained from the previous response:

GET /customers?nextToken=eyJwYXlsb2FkIjp7ImlkIjoiY3VzdG9tZXIxMjMifSwicGFnZVNpemUiOjIwLCJxdWVyeUNvbnRleHQiOnsiZmlsdGVyQnkiOltbeyJmaXJzdCI6InN0YXR1cyIsInNlY29uZCI6eyJ0eXBlIjoiRVEifX0sWyJBQ1RJVkUiXV1dLCJzb3J0QnkiOnsiaWQiOiJBU0MifSwic2VhcmNoT24iOm51bGx9LCJ0b2tlblR5cGUiOiJORVhUIn0=

This request will retrieve the next page of customers after the last one from the first page.

pageSize and other parameters passed to fetch the first page are not required to be passed in consecutive requests as this information is available within the nextToken and will be conidered when returning next pages.