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

# Pagination and incremental pulls

> Walk a collection once, then only ask for what changed.

## Paging

Every collection returns the same envelope:

```json theme={null}
{ "object": "list", "resource": "invoices", "data": [ … ], "has_more": true, "next_cursor": "eyJ…" }
```

A page holds **50 records unless you ask for more**, up to 200 with `?limit=200`. Keep
calling with `?cursor=<next_cursor>` until `has_more` is `false`. The `curl`
examples on this site use `$BASE` and `$VENSIGHT_KEY`, set as in the
[Quickstart](https://docs.vensight.ai/quickstart.md).

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

BASE = "https://app.vensight.ai/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['VENSIGHT_KEY']}"}

cursor, rows = None, []
while True:
    params = {"limit": 200, **({"cursor": cursor} if cursor else {})}
    r = requests.get(f"{BASE}/invoices", params=params, headers=HEADERS, timeout=30)
    r.raise_for_status()
    page = r.json()
    rows += page["data"]
    if not page["has_more"]:
        break
    cursor = page["next_cursor"]
```

```typescript TypeScript theme={null}
const BASE = "https://app.vensight.ai/api/v1";
const headers = { Authorization: `Bearer ${process.env.VENSIGHT_KEY}` };

const rows: unknown[] = [];
let cursor: string | null = null;
do {
  const params = new URLSearchParams({ limit: "200" });
  if (cursor) params.set("cursor", cursor);
  const res = await fetch(`${BASE}/invoices?${params}`, { headers });
  if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
  const page = await res.json();
  rows.push(...page.data);
  cursor = page.has_more ? page.next_cursor : null;
} while (cursor);
```

```bash curl theme={null}
curl "$BASE/invoices?limit=200" -H "Authorization: Bearer $VENSIGHT_KEY"
# then, with the next_cursor from that response:
curl "$BASE/invoices?limit=200&cursor=eyJ…" -H "Authorization: Bearer $VENSIGHT_KEY"
```

> [!WARNING]
>
> **Do not build a cursor yourself.** It is opaque and its format is not part of this
> contract. Use the one you were given, or start again from the beginning. A cursor that has
> been edited or cut short is refused with `400 invalid_query`.

## Ordering, and why it matters for syncing

Records come back **oldest change first**, ordered by when they last changed and then by
id. That means a new change always lands *behind* your cursor, so a walk that takes an
hour still sees every record. A newest-first list would put new records ahead of your
cursor and you would never reach them.

## Only what changed

Every collection accepts `updated_since`:

```bash theme={null}
curl "$BASE/vendors?updated_since=2026-09-01T00:00:00Z" \
  -H "Authorization: Bearer $VENSIGHT_KEY"
```

The pattern for a scheduled job:

1. Remember the highest `updated_at` you have successfully stored.
2. Next run, ask for `updated_since=<that value>`.
3. Page until `has_more` is false.

Use the value from the **records you stored**, not the clock on your own machine, so a job
that dies halfway resumes from what it actually stored rather than from when it started.

For [events](https://docs.vensight.ai/api-reference/events/list.md), [settings changes](https://docs.vensight.ai/api-reference/settings-changes/list.md),
[screening answers](https://docs.vensight.ai/api-reference/screening-answers/list.md) and the change feed, which are
never changed after they are written, `updated_since` filters on the time they were written
(`occurred_at` or `answered_at`). Each endpoint's reference page names the field.

> [!NOTE]
>
> `updated_since` is inclusive, so the boundary record comes back again on the next run.
> Upsert on `id` and that costs you one repeated record per collection per run. The
> alternative, an exclusive boundary, could drop a record written in the same millisecond.

## The change feed

[`/v1/changes`](https://docs.vensight.ai/api-reference/changes/list) is every create and update across every
collection, in order:

```json theme={null}
{
  "id": 41207,
  "event_name": "invoices.status_changed",
  "resource": "invoices",
  "resource_id": "9c2a7d10-4e8b-4f3a-b6d2-1a7e5c9f0b84",
  "vendor_id": "6f1c2a4e-8b1d-4c3a-9e57-2d4b8a1f0c93",
  "action": "updated",
  "occurred_at": "2026-09-09T02:14:07.221Z",
  "payload": { "field": "status", "from": "approved", "to": "paid" }
}
```

It is written by the database for every change, rather than by application code, so it does
not depend on anyone remembering to record a change. Each entry is the same change a
webhook announces: webhook `evt_41207` is entry `41207` here. That makes it the way to
catch up after a missed webhook; see [Webhooks](https://docs.vensight.ai/webhooks.md#catching-up-after-missed-deliveries).

## Filters

Beyond `updated_since`, collections whose records belong to a vendor accept `vendor_id`,
and each collection has its own short list of exact-match filters: `status` on invoices,
`event_type` on events, `event_name` on the change feed, and so on. They differ by
collection, so check each endpoint's reference page, which lists them with the values each
one accepts. A filter the collection does not have is refused with `400`, and the message
lists the ones it does accept.


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