# Pagination

#### API endpoints that support pagination

| API                                                                                                       | Sorted Order                                                                                                                                                                                                                                           |
| --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [Get all payments from payment service](/api-resources/payments/get-all-payments-from-payment-service.md) | <ul><li><code>created\_at</code></li><li><code>id</code></li></ul><p>Returns the most recently created payments first. If multiple payments are created at the same time, they are returned in reverse alphabetical order of their <code>id</code></p> |

We use cursor-based pagination for endpoints that list resources. The cursors used for pagination have **no inherent relationship** to the resources. These endpoints share a common structure, accepting the following parameters: `limit`, `before` and `after` . The response includes: `data` , an array containing the current page of resources, and `page_info` , which holds information about the current page.\
\
The `page_info` object contains a `start_cursor` that points to the first resource of the current page, `end_cursor` which points to the last resource of the current page, `has_previous_page` and `has_next_page` which indicate if the resource has a previous and next page respectively. \
\
Each cursor can be passed into  either the `before` or `after` parameters to return the resources immediately before or after the provided cursor. These parameters are mutually exclusive. You can use either the `before` or `after` parameter, but not both simultaneously. If **both** `before` and `after` are passed, an error will be returned by the API server. If no cursors are passed into `before` or `after`, the API returns the first page, containing the newest resources.&#x20;

#### Sample Response

```json
{
  "data": [ ... ]
  "page_info": {
    "has_next_page": true,
    "has_previous_page": true,
    "start_cursor": "WyIyMDIzLTA1LTEyVODowMCIsIjaaB0NCDE0OjI3Z25QRXVyYm9YTldOjEyLjczNCswaTzk5QyJd",
    "end_cursor": "WyIyMDdOjEyLjczLTA1LTjI3Z25QRXVyYm9YVODIzDE0Ok5QyJdTlowMCIsIjaaB0NCNCswaTzEy",
  }
}
```

#### Sample Usage

```
// Referencing the sample response

// Using before
// Calling GET /v1/payment-services/:payment_service_id?limit=20&before=${start_cursor}
Returns the previous page of resources and its page information

// Using after
// Calling GET /v1/payment-services/:payment_service_id?limit=20&after=${end_cursor}
Returns the next page of resources and its page information

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guide.pay.gov.sg/start-an-api-integration/pagination.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
