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

# Pagination and Delta Sync

> Page through list endpoints, sync only what changed, and look up jobs by your own internal ID

Most list endpoints in the v2 API are offset-paginated and built for incremental reconciliation. A few short lists return every row at once; the note below names them. This guide covers the four building blocks you need to keep an external system in step with Classet:

* **Offset pagination** with `page` / `limit` and the `{ data, meta }` envelope, on every paginated list endpoint
* **Cursor pagination** with `?cursor=` and `meta.next_cursor`, on `GET /v2/candidates` and `GET /v2/applications`
* **Delta sync** with `?updated_since=` so you fetch only what changed, on `GET /v2/jobs`, `GET /v2/candidates`, `GET /v2/applications` and `GET /v2/jobs/{id}/applications`
* **External-ID lookup** with `?external_id=` so you can find a job by *your* identifier, on `GET /v2/jobs` only

Most examples use `GET /v2/jobs`. Authenticate with your API key in the `X-API-KEY` header (see [Migration from v1](/docs/guides/migration-from-v1.md)).

```
Base URL: https://api.classet.ai/v2
```

***

## The list envelope

Every paginated endpoint returns a `data` array plus a `meta` object:

```json theme={null}
{
  "data": [ /* array of resources */ ],
  "meta": {
    "page": 1,
    "limit": 20,
    "total": 142
  }
}
```

| Field | Type | Description |
| - | - | - |
| `data` | array | The page of results |
| `meta.page` | integer | The page that was returned (echoes your request) |
| `meta.limit` | integer | The page size that was applied |
| `meta.total` | integer | Total count of records matching the query, across all pages — *after* any `updated_since` / `external_id` filter is applied. **An estimate on large collections** (see below) |

> [!NOTE]
>
> **`meta.total` is an estimate, not a guarantee.** On large collections the count comes from database statistics rather than a full scan, so it can drift slightly from the true row count; for small result sets it is exact. Use it for progress bars and page-count hints — but terminate pagination on a **short page** (fewer than `limit` items), never on reaching `meta.total`.

`meta.total` is the filtered total, so an approximate page count is:

```
totalPages ≈ Math.ceil(meta.total / meta.limit)
```

***

## Offset pagination

Two query parameters control paging:

| Parameter | Type | Default | Bounds | Notes |
| - | - | - | - | - |
| `page` | integer | `1` | `>= 1` | 1-indexed |
| `limit` | integer | `20` | `1`–`50` | **Max is 50.** Requesting more than 50 is rejected as a validation error |

`GET /v2/jobs` results are ordered by `updated_at` **descending** (most recently changed first; jobs with no `updated_at` sort last).

```bash curl theme={null}
# Second page of 25 jobs
curl -s "https://api.classet.ai/v2/jobs?page=2&limit=25" \
  -H "X-API-KEY: $CLASSET_API_KEY"
```

```typescript TypeScript theme={null}
async function listJobs(params: Record<string, string | number> = {}) {
  const query = new URLSearchParams(
    Object.entries(params).map(([k, v]) => [k, String(v)]),
  );
  const res = await fetch(`https://api.classet.ai/v2/jobs?${query}`, {
    headers: { "X-API-KEY": process.env.CLASSET_API_KEY! },
  });
  if (!res.ok) throw new Error(`List jobs failed: ${res.status}`);
  return res.json() as Promise<{
    data: Array<{ job_id: string; external_id: string | null; updated_at: string | null }>;
    meta: { page: number; limit: number; total: number };
  }>;
}

const { data, meta } = await listJobs({ page: 2, limit: 25 });
console.log(`Page ${meta.page} of ${Math.ceil(meta.total / meta.limit)}`);
```

### Iterating every page

Walk from page 1 until you receive a **short page** (fewer items than `limit`) — don't stop on `meta.total`, which is an estimate on large collections:

```typescript theme={null}
// Uses listJobs() from the offset pagination example.
async function listAllJobs(extra: Record<string, string | number> = {}) {
  const limit = 50; // max page size
  const all: unknown[] = [];
  let page = 1;

  while (true) {
    const { data } = await listJobs({ ...extra, page, limit });
    all.push(...data);
    if (data.length < limit) break; // short page = last page
    page++;
  }
  return all;
}
```

The [TypeScript SDK](/docs/guides/sdk-and-code-samples.md#iterate-whole-collections-with-listall)'s `listAll()` iterators use exactly this short-page rule.

> [!NOTE]
>
> Results are ordered by `updated_at` descending. If jobs are being edited while you page through a large list, offset paging can shift rows between pages. For a stable snapshot, page through quickly, or use `updated_since` (below) to scope to a narrow, mostly-static window and dedupe by `job_id`.

***

## Cursor pagination

`GET /v2/candidates` and `GET /v2/applications` also take an opaque `cursor`. Offset pages shift when rows are written while you read, so a record can be skipped or seen twice; a cursor doesn't shift. **Prefer the cursor for full syncs of candidates and applications.**

| Parameter | Type | Notes |
| - | - | - |
| `cursor` | string | The `meta.next_cursor` from the previous response. Omit it on the first request. Pass it instead of `page` |
| `limit` | integer | Same `1`–`50` bounds as offset paging |

Both endpoints return `meta.next_cursor` on every response, including the first page, so you can start a cursor walk without a cursor. It is `null` on the last page. Stop when it is `null`; don't page until you reach `meta.total`, which is an estimate.

```typescript theme={null}
async function listAllApplications(extra: Record<string, string> = {}) {
  const all: unknown[] = [];
  let cursor: string | null = null;

  do {
    const q = new URLSearchParams({ ...extra, limit: "50" });
    if (cursor) q.set("cursor", cursor);
    const res = await fetch(`https://api.classet.ai/v2/applications?${q}`, {
      headers: { "X-API-KEY": process.env.CLASSET_API_KEY! },
    });
    if (!res.ok) throw new Error(`List applications failed: ${res.status}`);
    const { data, meta } = await res.json();
    all.push(...data);
    cursor = meta.next_cursor; // null on the last page
  } while (cursor);

  return all;
}
```

Treat the cursor as opaque: don't build or edit one yourself. A malformed cursor returns `400 validation_error`. A cursor combines with the other filters, including `updated_since`, so long as you send the same filters on every page.

***

## Incremental sync with `updated_since`

Pass `?updated_since=<ISO 8601>` to return only jobs whose `updated_at` is **greater than or equal to** that timestamp. This is the delta-sync filter — instead of re-pulling every job on each run, you fetch just what moved since your last sync.

| Parameter | Type | Description |
| - | - | - |
| `updated_since` | string (ISO 8601) | Return jobs with `updated_at >= updated_since`. Must include a timezone offset (a trailing `Z` or `±hh:mm`). |

> [!WARNING]
>
> The timestamp **must carry a timezone offset**. `2026-06-01T00:00:00Z` and `2026-06-01T00:00:00+00:00` are valid; a bare `2026-06-01T00:00:00` (no offset) is rejected as a validation error.

```bash theme={null}
curl -s "https://api.classet.ai/v2/jobs?updated_since=2026-06-01T00:00:00Z&limit=50" \
  -H "X-API-KEY: $CLASSET_API_KEY"
```

The filter combines with pagination: `meta.total` is the count of jobs in the window, so you page through exactly as you would an unfiltered list.

> [!NOTE]
>
> The comparison is **inclusive** (`>=`). If you pass the exact `updated_at` of the last record you saw, that record comes back again on the next run. This is intentional — it guarantees you never miss a job that changed in the same instant as your cursor. Make your write side **idempotent** (upsert keyed on `job_id`) and the boundary overlap is harmless.

### Choosing your cursor

After each sync, store the **maximum `updated_at`** you observed in the page, not the wall-clock time you ran the job. Using the data's own timestamp avoids clock-skew gaps:

```typescript theme={null}
// `data` is a page from listJobs() in the offset pagination example.
let high: string | null = null;
for (const job of data) {
  if (job.updated_at && (!high || job.updated_at > high)) high = job.updated_at;
}
// persist `high` as next run's updated_since
```

***

## Candidates: `changed_at`, not `updated_at`

`GET /v2/candidates?updated_since=` works the same way, with one difference that matters: it filters on **`changed_at`**, not `updated_at`.

| Field | Meaning |
| - | - |
| `updated_at` | When the candidate record itself last changed. |
| `changed_at` | The later of `updated_at` and the newest change to any of the candidate's interview calls. **This is what `updated_since` compares against.** |

Interview results, transcripts, tags and evaluations land on the call, often without touching the candidate record. A cursor keyed on `updated_at` never sees them: the candidate keeps an older `updated_at`, so it is either skipped or re-fetched forever. Use `changed_at` to detect change.

> [!WARNING]
>
> **Advance your candidate cursor to a timestamp captured *before* the poll started, minus a 5-minute safety lag. Do not use the maximum `changed_at` you received.**
>
> Candidate results are ordered by `created_at`, but selected by `changed_at`, and the two are unrelated. A candidate that changes while you are mid-poll lands at an arbitrary position in the ordering, roughly half the time on a page you have already fetched. It is absent from this poll. If you then advance to the maximum `changed_at` you saw, your cursor moves past that change and the candidate is never returned again. A pre-poll timestamp makes it reappear next cycle: occasional duplicates instead of silent misses.
>
> The lag covers two clock effects a pre-poll cursor alone does not: our timestamps are transaction *start* time, so a long batch write can become visible with a timestamp earlier than your cursor; and `poll_started` is your clock while `changed_at` is ours.

```typescript theme={null}
const SAFETY_LAG_MS = 5 * 60 * 1000;

// Walk every page of GET /v2/candidates with the cursor.
async function* listAllCandidates(filters: Record<string, string> = {}) {
  let next: string | null = null;
  do {
    const q = new URLSearchParams({ ...filters, limit: "50" });
    if (next) q.set("cursor", next);
    const res = await fetch(`https://api.classet.ai/v2/candidates?${q}`, {
      headers: { "X-API-KEY": process.env.CLASSET_API_KEY! },
    });
    if (!res.ok) throw new Error(`List candidates failed: ${res.status}`);
    const { data, meta } = await res.json();
    yield* data;
    next = meta.next_cursor; // null on the last page
  } while (next);
}

async function pollCandidates(cursor: string | null) {
  const pollStarted = new Date();               // capture BEFORE the first request
  for await (const candidate of listAllCandidates(cursor ? { updated_since: cursor } : {})) {
    await upsert(candidate);                    // your idempotent write, keyed on candidate_id — duplicates are harmless
  }
  // Only after the whole poll succeeded. A partial failure must leave the cursor untouched.
  return new Date(pollStarted.getTime() - SAFETY_LAG_MS).toISOString();
}
```

The jobs rule above ("store the maximum `updated_at`") is safe for jobs because that list is ordered by `updated_at`: a row that changes mid-poll moves to the front, ahead of where you are reading, so you see it. Candidates are ordered by `created_at`, which is why the rule differs.

What the candidate cursor cannot express:

* **Deletions.** A removed candidate simply stops appearing; there is no tombstone. Reconcile with a periodic full walk if you need to expire records.
* **Job-field edits.** `job_title` on a candidate does not move the candidate cursor; a title edit would otherwise re-emit every candidate on the job. Track jobs with their own `updated_since`.

***

## Applications: the same pre-poll watermark

`GET /v2/applications?updated_since=` is the endpoint for syncing a pipeline across every job. Like candidates, it is ordered by `created_at`, not by the time the application changed, so the same rule applies: **advance your watermark to a timestamp captured before the poll started, minus 5 minutes. Never store the maximum `updated_at` you received.** An application that changes mid-poll can land on a page you've already read; a pre-poll watermark returns it next cycle instead of losing it.

Walk each poll with `cursor` rather than `page`, and upsert keyed on the application `id` so the overlap from the safety lag is harmless:

```typescript theme={null}
// Uses listAllApplications() from the cursor pagination example.
async function pollApplications(watermark: string | null) {
  const pollStarted = new Date(); // capture BEFORE the first request
  const filters: Record<string, string> = watermark ? { updated_since: watermark } : {};
  for (const application of await listAllApplications(filters)) {
    await upsert(application); // keyed on id
  }
  // Only after the whole poll succeeded.
  return new Date(pollStarted.getTime() - 5 * 60 * 1000).toISOString();
}
```

`GET /v2/jobs/{id}/applications` takes `updated_since` too, with the same rule, but has no cursor — use it for one job, and `GET /v2/applications?job_id=` when you want a cursor.

***

## Looking up a job by your internal ID

When you create or update a job you can attach your own identifier via `external_id` (see the `external_id` field on `POST /v2/jobs`). It's stored as-is and is independent of any ATS sync ID. To find that job later without holding onto the Classet `job_id`, filter the list by `?external_id=`. Only `GET /v2/jobs` accepts this filter:

| Parameter | Type | Description |
| - | - | - |
| `external_id` | string | Return only jobs whose `external_id` matches **exactly** (your internal job ID). |

```bash curl theme={null}
curl -s "https://api.classet.ai/v2/jobs?external_id=CC-REQ-48217" \
  -H "X-API-KEY: $CLASSET_API_KEY"
```

```typescript TypeScript theme={null}
// Uses listJobs() from the offset pagination example.
async function findJobByExternalId(externalId: string) {
  const { data } = await listJobs({ external_id: externalId });
  return data[0] ?? null; // external_id is unique within your org
}

const job = await findJobByExternalId("CC-REQ-48217");
if (job) console.log("Classet job_id:", job.job_id);
```

This returns the standard paginated envelope — the match (if any) is the first element of `data`. `external_id` and `updated_since` can be combined, e.g. "did *this* job change since my last sync?"

> [!NOTE]
>
> `external_id` is **your** identifier (e.g. `CC-REQ-48217`). It is distinct from the ATS remote ID, which is surfaced separately as `remote_job_id` and only for `ats_sync` organizations.

***

## Pattern: full resync vs. incremental sync

A robust integration does a **full resync** the first time (or when rebuilding state), then **incremental** runs keyed on the last cursor. Both use the same list call — the only difference is whether `updated_since` is present.

```typescript TypeScript theme={null}
type Job = {
  job_id: string;
  external_id: string | null;
  title: string;
  updated_at: string | null;
};

async function fetchJobsPage(page: number, updatedSince?: string) {
  const q = new URLSearchParams({ page: String(page), limit: "50" });
  if (updatedSince) q.set("updated_since", updatedSince);

  const res = await fetch(`https://api.classet.ai/v2/jobs?${q}`, {
    headers: { "X-API-KEY": process.env.CLASSET_API_KEY! },
  });
  if (!res.ok) throw new Error(`List jobs failed: ${res.status}`);
  return res.json() as Promise<{
    data: Job[];
    meta: { page: number; limit: number; total: number };
  }>;
}

/**
 * Sync jobs into your store.
 * - First run: pass no cursor -> full resync of every job.
 * - Later runs: pass the cursor you saved -> only changed jobs.
 * Returns the new cursor (max updated_at seen) to persist for next time.
 */
async function syncJobs(cursor?: string): Promise<string | undefined> {
  const limit = 50; // must match the limit fetchJobsPage requests
  let page = 1;
  let high = cursor;
  const seen = new Set<string>();

  while (true) {
    const { data } = await fetchJobsPage(page, cursor);

    for (const job of data) {
      if (seen.has(job.job_id)) continue; // dedupe inclusive-boundary repeats
      seen.add(job.job_id);

      await upsertJob(job); // your idempotent write, keyed on job_id

      if (job.updated_at && (!high || job.updated_at > high)) {
        high = job.updated_at;
      }
    }

    if (data.length < limit) break; // short page = last page
    page++;
  }

  return high; // persist; pass back in as `cursor` next run
}

// First ever run — full resync, no cursor:
let cursor = await syncJobs();

// Every subsequent run — incremental since last cursor:
cursor = await syncJobs(cursor);
```

```bash curl theme={null}
# 1. FULL RESYNC — first run, no cursor. Page until a short page (< limit items).
curl -s "https://api.classet.ai/v2/jobs?page=1&limit=50" \
  -H "X-API-KEY: $CLASSET_API_KEY"
# ...repeat with page=2, page=3, ... until a page returns fewer than 50 items

# Record the highest updated_at you saw, e.g. 2026-06-20T14:00:00Z

# 2. INCREMENTAL — later runs, scoped to changes since that cursor.
curl -s "https://api.classet.ai/v2/jobs?updated_since=2026-06-20T14:00:00Z&page=1&limit=50" \
  -H "X-API-KEY: $CLASSET_API_KEY"
# Page through this smaller window the same way; dedupe by job_id on the boundary.
```

> [!TIP]
>
> Run a periodic **full resync** (e.g. nightly or weekly) alongside your frequent incremental runs. It backfills anything an incremental run could miss — a record hard-deleted upstream, or a cursor that drifted — and self-heals your mirror.

***

## Read consistency

`GET` requests may be served from a **read replica** with sub-second replication lag. In rare cases, a `GET` issued immediately after a write can briefly return the prior state — a job you just PATCHed shows the old title, or a candidate you just created is missing from the list for a moment.

* **Most write responses return identifiers, not the resource.** A `POST`/`PATCH` usually answers with the id it created or changed inside `data` — `{ "id": ... }`, `{ "job_id": ... }`, `{ "script_id": ... }` or `{ "candidate_id": ... }` (with the interview links), depending on the endpoint. To read the new state, `GET` the resource by that id. The exceptions return the resource itself: `POST /v2/message-automations` and `POST /v2/message-automations/{id}/duplicate` return the full automation, `PATCH /v2/message-automations/{id}` returns the automation summary, and `PATCH /v2/agent-settings` and `PUT /v2/webhooks` return the updated settings.
* **Retry that `GET` briefly on a miss.** A `404`, or the old values, right after a write usually means the replica hasn't caught up yet; wait a few hundred milliseconds and try again before treating it as an error.
* **Don't build read-after-write assertions** into your integration (e.g. "create, then immediately list and expect to see it").
* Delta syncs are unaffected in practice: the inclusive `updated_since` boundary plus your periodic full resync absorb any sub-second lag.

***

## Quick reference

| Goal | Request |
| - | - |
| First page, default size | `GET /v2/jobs` |
| Specific page, max size | `GET /v2/jobs?page=3&limit=50` |
| Everything changed since a time | `GET /v2/jobs?updated_since=2026-06-01T00:00:00Z` |
| Find a job by your own ID | `GET /v2/jobs?external_id=CC-REQ-48217` |
| Did my job change since last sync? | `GET /v2/jobs?external_id=CC-REQ-48217&updated_since=2026-06-01T00:00:00Z` |
| Walk every application with a cursor | `GET /v2/applications?limit=50`, then `?cursor=<meta.next_cursor>` until it is `null` |
| Applications changed since a watermark | `GET /v2/applications?updated_since=2026-06-01T00:00:00Z` |

> [!NOTE]
>
> Paginated v2 list endpoints take `page` / `limit` and return the `{ data, meta: { page, limit, total } }` envelope. `limit` defaults to 20 with a maximum of 50, except `GET /v2/candidates/{id}/messages`, which defaults to 50 with a maximum of 100. These list endpoints are not paginated and return every row in `{ data }`: `GET /v2/scripts`, `GET /v2/message-automations`, `GET /v2/tags` and `GET /v2/webhooks`. `GET /v2/jobs/{id}/stages` is also unpaginated; its `meta` carries only `source`. `cursor` is accepted only by `GET /v2/candidates` and `GET /v2/applications`; `updated_since` by `GET /v2/jobs`, `GET /v2/candidates`, `GET /v2/applications` and `GET /v2/jobs/{id}/applications`; and `external_id` by `GET /v2/jobs` only.


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