# Many pages in one request: collect a list as CSV

> POST /v1/collect pages a list endpoint for you, keeps each item once and stops at your item or money limit; download the result as CSV or JSON lines.

Canonical page: https://okdata.online/docs/collect/

When you need a few hundred items rather than one page, `POST /v1/collect` does the paging for you. It calls a list endpoint page after page with your parameters, keeps each item once (by its `id`), and stops when it has enough. You follow the job with `GET /v1/collect/{id}` and download the items as CSV or JSON lines.

Starting a job is free. Every page it fetches is an ordinary call: the same price, the same balance hold, the same key limits and rate limits, and it shows in your call log (entry `collect`). A job of 17 pages of [TikTok video search](/apis/tiktok/videos/search/) costs what 17 calls cost: $0.034.

## Start a job

```bash
curl -s "https://api.okdata.online/v1/collect" \
  -H "Authorization: Bearer $OKDATA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"capability": "tiktok.videos.search", "params": {"query": "ai agents"}, "max_items": 500, "max_price": "0.05"}'
```

| Field | Meaning |
| --- | --- |
| `capability` | A list endpoint (one that returns `data.items` and a `page`). |
| `params` | Its parameters, as for a single call. A `cursor` here starts from that page. |
| `max_items` | Stop once this many different items are in. 1 to 1,000; 100 when left out. The last page is kept whole, so you may get a few more. |
| `max_price` | Optional. The most all pages together may cost, in US dollars. A page that could pass it is not fetched. |

The answer (HTTP 202) is the job:

```json
{
  "code": "ok",
  "data": {
    "id": "col_3f9c…",
    "status": "running",
    "stop_reason": null,
    "items": 0,
    "pages": 0,
    "charged": "0",
    "next_cursor": null,
    "download": { "csv": "https://api.okdata.online/v1/collect/col_3f9c….csv?token=…", "jsonl": "https://api.okdata.online/v1/collect/col_3f9c….jsonl?token=…" }
  }
}
```

An account runs up to 3 jobs at once.

## Follow it

`GET /v1/collect/{id}` gives `status` (`running`, `done` or `failed`), `items` and `pages` so far, `charged` so far, `next_cursor` (where to go on from with a normal call), and `request_ids`, the receipt of every page (`GET /v1/calls/{request_id}`). It is free. Poll every few seconds until `status` is no longer `running`.

`stop_reason` says why it stopped:

| `stop_reason` | Status | Meaning |
| --- | --- | --- |
| `max_items` | done | It has `max_items` items. |
| `max_price` | done | The next page could pass `max_price`. |
| `no_more_pages` | done | The listing ended. |
| `no_new_items` | done | Three pages in a row brought nothing new. |
| `insufficient_balance` | done | The balance does not cover another page. Top up and start again. |
| `key_budget_exceeded` | done | The key reached a spending limit. |
| `failures` | failed | Three pages in a row failed, each after waiting and trying again. |
| `interrupted` | failed | The job stopped on our side. Start it again; what it had is kept. |

A job that stops early keeps every item it has: download them the same way.

## Download

- `GET /v1/collect/{id}.csv`: one row per item. Columns `id`, `url`, `title`, `text`, `published_at` come first, then the other fields, with the author and the counts as `author.name`, `metrics.likes` and so on. Image links are joined by spaces. UTF-8 with a byte order mark, so Excel shows Chinese and emoji correctly.
- `GET /v1/collect/{id}.jsonl`: one item per line, as the endpoint returns it.

Both work with your key, or without one through the `download` links in the job, which carry a token. Anyone with a link can download those items, so share it only with people who may see them. Jobs and their items are kept 7 days.

## From MCP and the console

The MCP tool `collect_items` takes the same things as `call` plus `max_items` and `max_price`, and answers the job ID and the download links; `collect_items` with `job_id` says how it is going. See the [MCP reference](/docs/mcp/).

In the console Playground, list endpoints have a "Collect N items as CSV" button under Run: it shows the progress and offers the CSV when the job ends.

## When to page yourself

Use your own loop ([pagination](/docs/pagination/)) when you want to look at each page before deciding to go on, or need more than 1,000 items. A job reads one listing; for several keywords, start one job per keyword.

Updated 2026-12-02
