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

# Pagination

> Fetch every record from a list endpoint using cursors

List endpoints return results in pages. You control the page size with `limit` and move through pages with `cursor`.

## How it works

1. Send the first request without a `cursor`.
2. Read `data.context.hasMore` in the response.
3. If it's `true`, send the same request again with `cursor` set to `data.context.nextCursor`.
4. Stop when `hasMore` is `false`.

```json theme={null}
{
  "ok": true,
  "data": {
    "vendors": [],
    "context": {
      "count": 120,
      "hasMore": true,
      "nextCursor": "30"
    }
  }
}
```

<Tip>
  Treat the cursor as an opaque value and pass it back unchanged. Drive the loop with `hasMore`, not by comparing the number of results to `limit`. A short page doesn't prove you've reached the end.
</Tip>

## Page size

Most list endpoints accept a `limit` of 1 to 100. The default varies by endpoint, so check the endpoint page. Keep every other filter identical across pages, otherwise the cursor won't line up.

## Example

<CodeGroup>
  ```javascript JavaScript theme={null}
  async function fetchAllVendors() {
    const vendors = [];
    let cursor;

    do {
      const params = new URLSearchParams({ limit: '100' });
      if (cursor) params.set('cursor', cursor);

      const response = await fetch(`https://api.pazy.io/v1.0/vendors?${params}`, {
        headers: { Authorization: 'Api-Key YOUR_API_KEY' },
      });
      const { data } = await response.json();

      vendors.push(...data.vendors);
      cursor = data.context.hasMore ? String(data.context.nextCursor) : undefined;
    } while (cursor);

    return vendors;
  }
  ```

  ```python Python theme={null}
  import requests

  def fetch_all_vendors():
      vendors = []
      cursor = None

      while True:
          params = {"limit": 100}
          if cursor is not None:
              params["cursor"] = cursor

          response = requests.get(
              "https://api.pazy.io/v1.0/vendors",
              headers={"Authorization": "Api-Key YOUR_API_KEY"},
              params=params,
          )
          data = response.json()["data"]

          vendors.extend(data["vendors"])
          if not data["context"]["hasMore"]:
              return vendors
          cursor = data["context"]["nextCursor"]
  ```
</CodeGroup>

## Endpoints that use it

[Vendor List](/apis/vendor-list), [Invoice List](/apis/invoice-list), [Purchase Order List](/apis/po-list), [Expense List](/apis/expense-list), [Reimbursement List](/apis/reimbursement-list), [Payment Request List](/apis/payment-request-list) and [User List](/apis/user-list).

Some small lists return everything in one response, such as the [TDS](/apis/taxes-tds) and [GST](/apis/taxes-gst) tax lists.

<Note>
  The `context` fields differ slightly between endpoints. For example, `count` means the total matches on some and the size of the current page on others, and `nextCursor` is a number on User List. Check the response table on the endpoint page when you rely on those details.
</Note>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.