# Pagination and filters

> Every list uses page and size, returns the same envelope and accepts search, Bogotá dates and ordering.

[Sandbox · coming soon]

The listing operations (`GET /v1/transactions`, `GET /v1/deposits`, `GET /v1/recharge-links`) share the same parameters and the same response envelope.

## Parameters

| Parameter            | Default     | What it does                                          |
| -------------------- | ----------- | ----------------------------------------------------- |
| `page`               | `1`         | Page, from 1.                                         |
| `size`               | `10`        | Items per page, from 1 to 100.                        |
| `search`             | —           | Full-text search over the fields each list documents. |
| `dateFrom`, `dateTo` | —           | `YYYY-MM-DD` dates in Bogotá time, inclusive.         |
| `orderBy`            | `createdAt` | Field to sort by; each list documents its own.        |
| `order`              | `DESC`      | `ASC` or `DESC`.                                      |

Each list adds its own filters: `type`, `status`, `method` and `currency` on transactions; `method` and `reference` on deposits; `status` on payment links.

## Response envelope

```json title="200"
{
  "data": [],
  "page": 1,
  "size": 10,
  "pages": 1,
  "count": 0,
  "total": 0
}
```

`count` is the items on this page and `total` the items on all of them; `pages` is at least 1.

## Walk every page

```js title="Node.js"
async function* allDeposits(dateFrom, dateTo) {
  for (let page = 1; ; page++) {
    const url = `https://sandbox.zulu.com.co/v1/deposits?page=${page}&size=100&dateFrom=${dateFrom}&dateTo=${dateTo}`;
    const response = await fetch(url, {
      headers: { Authorization: `Bearer ${process.env.ZULU_ACCESS_TOKEN}`, 'X-API-Key': process.env.ZULU_API_KEY },
    });
    const body = await response.json();

    yield* body.data;
    if (page >= body.pages) return;
  }
}
```

> **Sort by a stable field**
>
> If you walk a list while new items arrive, sort with `order=ASC` and bound it with `dateFrom`/`dateTo`: no page will shift under you.

## Errors

A parameter that can not be converted to its type answers before validation; one out of range answers with `values`:

| HTTP | error | cause | Description |
| --- | --- | --- | --- |
| 400 | `BadRequestApiError` | `invalid value for "%s": %s` | A URL parameter can not be converted to its type (for example `page=abc`). |
| 400 | `BadRequestApiError` | `error in struct validation` | One or more fields fail their validation. `values` carries one message per field, keyed by its JSON path, naming the Go validator that failed. |

**400 · size=500**

```json
{
  "error": "BadRequestApiError",
  "cause": "error in struct validation",
  "values": {
    "size": "failed validation on the \"lte\" tag with value required \"100\""
  }
}
```
