Pagination

Pagination, as a technique, helps to break big datasets into manageable chunks for optimised data retrieval, processing, and display.

How Pagination is Implemented in Pleo?

We follow a combined pagination approach, where we have implemented both offset and cursor based pagination techniques:

  • Offset: In this method, a starting point (offset) and a limit are mentioned to retrieve data subsets in a paginated format. For example, when an integration sends a request to an API endpoint, it must mention the maximum number of records (limit) to be returned in the response and must also specify the number of records to skip (offset) before starting the count.

    In Offset based pagination, the usual parameters sent in an API request are:
    • offset: Indicates the starting point of the dataset by specifying the number of records to be skipped.
    • limit: Indicates the maximum number of records to be returned in an API response.

      💡

      Note: limit and offset are usually used together. offset can be zero in the first request because in the subsequent requests, you can mention the number of records to skip, based on the last record sent in the first request.

Request message example:

https://external.pleo.io/v2/export-jobs?limit=10&offset=10
  • Cursor: In this method, a unique identifier or cursor indicates the last item returned in a query and accordingly determines the starting point of the next dataset. For example, when an integration sends a request to an API endpoint, the server returns the data along with a cursor pointing to the last item on the page. To continue to the next page, the integration sends the cursor to the server — the cursor acts as the indicator to return data starting after the cursor.

    In Cursor based pagination, the usual parameters sent in an API request are:
    • limit: Specifies the maximum number of records to be returned in an API response.
    • before: Paginates backwards, implying the records before the cursor would be retrieved in an API response.
    • after: Retrieves records starting after the cursor.

      💡

      Note: Either before or after is used in the request.

    • sorting_keys: Mentions specific sorting parameters to sort the records returned in an API response.
    • sorting_order: Mentions the direction of sorting the records — ascending or descending order.

      Request message example:
https://external.pleo.io/v2/export-jobs?limit=10&after=ThisIsTheEndCursor

In response, the usual attributes are:

  • startCursor: Indicates the starting point of the dataset returned in an API response.
  • endCursor: Indicates the last item of the dataset returned in an API response.
  • total: The total number of records returned in an API response.

    Response message example
    :
{
   "hasPreviousPage": false,
   "hasNextPage": true,
   "currentRequestPagination": {
      "sortingKeys": [
         
      ],
      "sortingOrder": [
         
      ],
      "parameters": {
         "company_id": [
            
         ]
      }
   },
   "startCursor": "ThisIsTheStartCursor",
   "endCursor": "ThisIsTheEndCursor",
   "total": 10
}

💡

Note: In the next request, the endCursor is referred to retrieve the next batch of items, starting from where the previous query has finished.