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

# Pagination

> Page through list endpoints with page and limit: the response shape, the sort order of each list, and how to read a list that changes while you page.

List endpoints return results one page at a time. You choose the page with `page` and its size with `limit`.

## Parameters

| Parameter | Description |
| - | - |
| `page` | Zero-based page number. The first page is `0`. Defaults to `0`. |
| `limit` | Items per page, from `1` to `100`. Defaults to `10`, or `100` on the payment batch lists. |

A `limit` above `100` or below `1` is rejected with `422`. It is not reduced to the maximum for you.

```bash theme={null}
curl "https://sandbox.api.afriex.com/api/v1/transaction?page=0&limit=100" \
  -H "x-api-key: YOUR_API_KEY"
```

## Response

Every paginated response has the same shape:

```json theme={null}
{
  "data": [ ... ],
  "total": 285,
  "page": 0
}
```

| Field | Description |
| - | - |
| `data` | The items on this page. |
| `total` | The number of items that match your filters, across all pages. |
| `page` | The page you asked for. |

There is no next-page cursor. You have reached the last page when `(page + 1) * limit` is at least `total`, or when `data` is empty.

## Sort order

Each list has a fixed order. You can't change it.

| Endpoint | Order |
| - | - |
| [List Transactions](/api-reference/endpoint/transactions/list) | Newest first, by creation time |
| [List Customers](/api-reference/endpoint/customers/list) | Alphabetical, by full name |
| [List Payment Methods](/api-reference/endpoint/payment-methods/list) | Most recently updated first |
| [List Payment Batches](/api-reference/endpoint/payment-batches/list), [List Batch Recipients](/api-reference/endpoint/payment-batches/list-recipients), [List Batch Sessions](/api-reference/endpoint/payment-batches/list-sessions) | Newest first, by creation time |

## Reading every page

Request pages in order until you reach the last one:

```typescript theme={null}
async function listAllTransactions(apiKey: string) {
  const limit = 100;
  const seen = new Map<string, unknown>();

  for (let page = 0; ; page++) {
    const res = await fetch(
      `https://sandbox.api.afriex.com/api/v1/transaction?page=${page}&limit=${limit}`,
      { headers: { "x-api-key": apiKey } },
    );
    const { data, total } = await res.json();

    // Key by ID so an item that shifts onto the next page is not counted twice.
    for (const tx of data) seen.set(tx.transactionId, tx);

    if (data.length === 0 || (page + 1) * limit >= total) break;
  }

  return [...seen.values()];
}
```

## Lists that change while you page

Each request counts its page from the start of the list at that moment. If items are added or reordered between your requests, the pages shift under you:

* **Transactions.** A transaction created while you page goes on page `0` and pushes every other item down by one. The last item on a page you already read then appears again at the top of the next page. Key the results by `transactionId`, as the example above does.
* **Payment methods.** The list is ordered by last update, so a payment method that changes while you page moves to page `0`. You can miss it on the page you were about to read. If you need a complete set, read the list a second time and merge the results by `paymentMethodId`.

To reconcile transactions, fix the window with `fromDate` and a `toDate` in the past. No new transaction can enter that window while you page, so the set stays stable. See [List Transactions](/api-reference/endpoint/transactions/list).

<Tip>
  Don't poll a list to see whether a transaction finished. Status changes arrive as [webhooks](/api-reference/endpoint/webhooks/transaction-events).
</Tip>


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