> ## Documentation Index
> Fetch the complete documentation index at: https://docs.treasuryprime.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pagination

Learn how to page through API results efficiently using Treasury Prime’s pagination methods. This guide explains cursor-based pagination and how to retrieve large sets of data in a structured way.

When listing all existing API objects, the returned list appears in reverse chronological order, with the most recently created accounts appearing first. Optional pagination parameters are described below.

##### Definition

<CodeGroup>
  ```bash bash theme={null}
  GET https://api.treasuryprime.com/$OBJECT_PATH
  ```
</CodeGroup>

| Parameter    | Type   | Required? | Description                                                                                                              |
| ------------ | ------ | --------- | ------------------------------------------------------------------------------------------------------------------------ |
| page\_cursor | string |           | Pagination cursor, value is the object ID.                                                                               |
| page\_size   | number |           | Limits the number of objects in the returned list, value must be a number greater than or equal to 1. Defaults to `100`. |
| from\_date   | string |           | Lists the objects created on the date provided and onwards. Date must be in ISO 8601 format ("YYYY-MM-DD").              |
| to\_date     | string |           | Lists the objects created before the date provided. Date must be in ISO 8601 format ("YYYY-MM-DD").                      |

Returns a list of objects with the optional pagination parameters applied.

##### Example Request

<CodeGroup>
  ```bash bash theme={null}
  $ curl "https://api.treasuryprime.com/counterparty?page_size=2&page_cursor=cp_10" \
      -u $API_KEY_ID:$API_KEY_VALUE
  ```
</CodeGroup>

##### Example Response

<CodeGroup>
  ```bash bash theme={null}
  {
      "data": [
          {
            "ach": {
              "account_number": "64141601",
              "account_type": "checking",
              "routing_number": "021001208"
            },
            "created_at": "2018-10-30T22:30:09Z",
            "id": "cp_9",
            "name": "John Smith",
            "updated_at": "2018-10-30T22:30:09Z",
            "userdata": null,
            "wire": null
          },
          {
            "ach": {
              "account_number": "54545454",
              "account_type": "checking",
              "routing_number": "021001208"
            },
            "created_at": "2018-10-30T22:20:09Z",
            "id": "cp_8",
            "name": "Jane Doe",
            "updated_at": "2018-10-30T22:20:09Z",
            "userdata": null,
            "wire": null
          }
      ],
      "page_next": "https://api.treasuryprime.com/counterparty?page_cursor=cp_8"
  }
  ```
</CodeGroup>

### Common Questions About Pagination:

* How do I page through results in Treasury Prime's API?
  * To paginate through results, utilize the `page_cursor` parameter in your API requests. This cursor points to a specific item in the dataset, enabling you to retrieve subsequent data segments.

* What is the best way to paginate API responses?
  * The recommended approach is to start with an initial request without the `page_cursor` parameter to fetch the first set of results. The API response will include a `page_next` field containing a URL with the `page_cursor` for the next set of results. Use this cursor in your subsequent requests to continue paging through the dataset.

* How does Treasury Prime handle pagination with large data sets?
  * Treasury Prime's API returns lists in reverse chronological order, displaying the most recently created items first. By using the `page_cursor` and `page_size` parameters, you can control the flow and volume of data retrieved, ensuring efficient handling of large datasets.

* What parameters should I use for cursor-based pagination?

  * `page_cursor`: A string representing the ID of the last item from the previous set of results. Include this in your request to fetch the next set.
  * `page_cursor`: An optional parameter to define the number of items returned per request. The default is 100, but it can be adjusted to meet your needs.
