# Pagination

URL: https://api-docs.vestta.io/pagination

Page through properties and leads with limit and offset.

List endpoints return results in pages, controlled by two query parameters:

| Parameter | Default | Range | Meaning |
| --- | --- | --- | --- |
| `limit` | `100` | 1–1000 | Maximum number of results in the page. |
| `offset` | `0` | ≥ 0 | Number of results to skip. |

A value outside its range returns [`422`](/errors#validation-errors). There are no cursors or `next` links.

## What `count` means

Both list endpoints report the total matching records across all pages, including when the requested page is empty.

| Endpoint | Order | `count` |
| --- | --- | --- |
| [List properties](/properties/list) | Last updated first, unless `sort` is set | **Total** matching properties, across all pages |
| [List leads](/leads/list) | Newest first | **Total** contacts, across all pages |

## Paging through properties

`count` is the total, so stop when `offset` reaches it:

```javascript [JavaScript]
async function listAllProperties() {
  const properties = []
  const limit = 100
  for (let offset = 0; ; offset += limit) {
    const url = `https://api.vestta.io/v1/properties?limit=${limit}&offset=${offset}`
    const response = await fetch(url, { headers: { 'X-Api-Key': process.env.VESTTA_API_KEY } })
    if (!response.ok) throw new Error(`Vestta API ${response.status}`)
    const page = await response.json()
    properties.push(...page.data)
    if (offset + limit >= page.count) return properties
  }
}
```

## Paging through leads

Stop when the offset reaches the total:

```python [Python]
import os

import requests

def list_all_leads():
    leads, limit, offset = [], 100, 0
    while True:
        response = requests.get(
            "https://api.vestta.io/v1/leads",
            headers={"X-Api-Key": os.environ["VESTTA_API_KEY"]},
            params={"limit": limit, "offset": offset},
        )
        response.raise_for_status()
        page = response.json()
        leads.extend(page["data"])
        if offset + limit >= page["count"]:
            return leads
        offset += limit
```

## Consistency

Pages are computed when each request arrives. If properties or leads change while you page through them, a result can move between pages and be skipped or returned twice. When you need a complete, exact copy, de-duplicate by `id`, and run the sync again later rather than relying on a single pass.

Filters are applied before pagination, including the map areas of [List properties](/properties/list#map-areas): `count` and the pages only contain matching properties.
