API reference
Unified scrape
Scrape one page with the level chosen for you. Works with an API key
5 min read
A unified scrape takes one URL and chooses how to scrape it: it starts at the level it judges right for the page and moves up a level when that one is not enough.
| Route | Does |
|-------|------|
| POST /api/v1/organizations/{org_id}/scraping/unified | Starts a scrape and answers its job |
| GET /api/v1/organizations/{org_id}/scraping/unified/{job_id} | The job's state and, when done, its result |
Both routes take the organisation's API key, as well as a dashboard session. They are not in the API reference yet. The SDKs have a method for each, from 0.7.0 (Python, TypeScript, Go, Java).
Access
- The key must be a live key. A test key answers
403withdetail.errortest_key_not_allowed. - The plan must include Extract (Kolektr) and the strategy engine (Nexus). Without both the answer is
403withdetail.errormodule_not_entitled; the body names the missingmoduleand listsmodules. - The call is gated like other work:
429when the organisation's data allowance is used up,402when a paid plan is unpaid (errors).
Start a scrape
curl -X POST https://api.kloakd.dev/api/v1/organizations/$ORG_ID/scraping/unified \
-H "Authorization: Bearer sk-live-..." -H "Content-Type: application/json" \
-d '{
"url": "https://books.toscrape.com/",
"prompt": "extract all book titles and prices"
}'
| Field | Type | Description |
|-------|------|-------------|
| url | string | Required. The page to scrape (http:// or https://) |
| prompt | string | What to extract, in plain words |
| mode | string | auto (the default), level1 or level2 |
| schema | object | {field: "selector"}, both strings. Left out, it is worked out from prompt |
| options | object | Scraping options |
| context | object | More context for the strategy engine |
| constraints | object | Constraints for the strategy engine |
| session_artifact_id | string | A login session to scrape with |
Response
{
"success": true,
"job_id": "…",
"level": "level1",
"status": "completed",
"escalation_path": [],
"message": "Scraping initiated at level1",
"metadata": null,
"auth_required": false,
"discovery_id": null
}
| Field | Type | Description |
|-------|------|-------------|
| success | boolean | true whenever the request was answered. It does not say the scrape worked: read status |
| job_id | string | The scrape's job. Read it with the status route |
| level | string | The level the scrape ran at: level1 or level2, or preflight when a login page stopped it |
| status | string | The scrape's state. failed and auth_required are described below |
| escalation_path | array | Each move to another level: from, to, reason, timestamp |
| message | string | A note on the answer |
| metadata | object or null | Further details, when the scrape gives any |
| auth_required | boolean | true when the page needs a login |
| discovery_id | string or null | With auth_required: the auth-chain discovery that was started (logins) |
Check status, not success. A scrape that failed currently answers HTTP 200 with success: true and status: "failed". The message still reads "Scraping initiated at …" and the answer carries no error text. The job_id of a failed answer may name no stored job, in which case reading it answers 404. Treat any answer whose status is failed as a failure.
A page behind a login
When the page is a login page the answer has level: "preflight", status: "auth_required", auth_required: true and a discovery_id. The job_id of this answer names no stored job: do not poll it. Log in (login sessions), then send the scrape again with session_artifact_id.
Long scrapes: 202
A scrape still running after about 85 seconds answers 202 with a job_id and a poll_url (/api/v1/organizations/{org_id}/handoff/{job_id}), as an extraction does. Poll it until status is completed (the response above is in result) or failed.
Read a scrape
curl https://api.kloakd.dev/api/v1/organizations/$ORG_ID/scraping/unified/$JOB_ID \
-H "Authorization: Bearer sk-live-..."
| Field | Type | Description |
|-------|------|-------------|
| id | string | The job |
| status | string | The job's state |
| level | string | The level it ran at |
| progress | integer or null | Progress |
| progress_detail | object or null | percentage, current_step, items_found, items_target and partial_results (the first few results) |
| created_at, updated_at, completed_at | string or null | Times |
| error | string or null | The error text of a failed job |
| result | object or null | What the scrape extracted, when it has completed |
| escalation_path | array | As above |
Only the organisation's own jobs are found; any other id answers 404.
Next steps
- Extract: one page with a schema you give
- Batch jobs: a list of URLs as one job
- Choosing an approach
