# Jobs

> One-off reads with durable jobs - parameters, render auto or browser, outputs and extraction, page discovery, results and retention.

A job is one read, or one discovery run, that Netscrape stores before it
answers. It keeps going if your connection drops, it's retried after transient
failures, and its result is kept for seven days. Every watch check is a job too.

## List jobs

`GET /v1/jobs` returns this account's jobs newest first by submission time.
Pass `limit` (1–100, default 25) and the opaque `next_cursor` as `after` for the
next page. Ordering is `(inserted_at DESC, id DESC)`; the ID breaks timestamp
ties. A null `next_cursor` ends the list. Do not use a job ID as a cursor.

## Submit a job

```sh
curl https://netscrapehq.com/v1/jobs \
  -H "Authorization: Bearer $NETSCRAPE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"url":"https://example.com","render":"auto"}'
```

Netscrape validates the request, stores it and answers `202` with the job and a
`Location` header. Nothing touches the site yet.

```json
{
  "id": "a99edbc9-09e7-48b7-9ee7-7e24188507dc",
  "type": "scrape",
  "status": "queued",
  "url": "https://example.com",
  "status_url": "/v1/jobs/a99edbc9-09e7-48b7-9ee7-7e24188507dc",
  "result_url": null,
  "expires_at": "2026-11-14T11:10:15.738685Z",
  "result_expires_at": "2026-11-20T11:10:15.738685Z"
}
```

Poll `GET /v1/jobs/:id` until `status` is `succeeded`, `failed` or `cancelled`,
or take a [job webhook](https://netscrapehq.com/docs/events.md#job-webhooks). Then download the result
from `result_url`.

## Parameters

| Parameter | Meaning |
| --- | --- |
| `url` | Required. An absolute public HTTP(S) URL, without credentials. |
| `render` | `auto` (default), `http` or `browser`. See [render modes](#render-modes). |
| `output` | `body` (default), `document`, `screenshot` or `responses`. Screenshots and captured responses need a browser. |
| `policy` | Per-request rules: robots.txt, pacing, scope and request limits. See [Politeness](https://netscrapehq.com/docs/politeness.md#robotstxt). Accounts that require robots.txt checks read a request without one as `{"robots": true}`, and refuse `"robots": false` with `403 robots_required`. |
| `extract` | With `output: "document"`: values to read by CSS selector, text pattern, keyword or JSON-LD type. |
| `render_options` | `sparse_text_bytes`, `http_accept` and `wait_for`. |
| `fetch` | HTTP controls: `method` (`GET` or `HEAD`), `headers` (`accept`, `accept-language`, `range`, `if-none-match`, `if-modified-since` only), `max_bytes` (up to 32,000,000), `follow_redirects`, `truncate`. |
| `settle_ms` | Browser wait after the page is ready: 0–5000 ms, default 2000. |
| `block_resources` | Skip images, fonts, media and trackers in the browser. Skipped by default for every output but screenshots. |
| `width` | Browser viewport width: 320–1920 pixels, default 1280. |
| `capture` | Required for `output: "responses"`: a URL substring naming the fetch/XHR responses to keep. |
| `locale` | `en-GB` (default) or `en-US`. |
| `deadline` | ISO 8601 time after which the job expires, capped at 24 hours. |
| `max_retries` | Automatic retries after transient failures: 0–2, default 2. |

Netscrape chooses the identity each request presents; you can't set a user
agent or send credentials or cookies.

## Render modes

- **`http`** reads the page over HTTP only.
- **`browser`** loads it in a real browser.
- **`auto`** reads over HTTP first and moves on to a browser only when the page
  needs one: a successful HTML page with a script and almost no visible text
  (under 80 bytes by default, `render_options.sparse_text_bytes` to change), a
  verification screen, or a `wait_for` condition. HTTP errors such as 403 or 429
  never trigger a browser.

`render_options.http_accept` lists text patterns that prove the HTTP read is
good enough, so a sparse page that matches them stays on HTTP.
`render_options.wait_for` waits for a CSS `selector`, some `text`, or both,
for up to `timeout_ms` (default 5,000):

```json
{
  "url": "https://transit.example/timetable",
  "render": "browser",
  "render_options": {"wait_for": {"selector": "table.departures", "text": "Platform", "timeout_ms": 8000}}
}
```

The result says what happened: `rendered` is `true` when a browser read the
page, `wait_satisfied` reports the wait, and an HTTP read of a script-built
shell says `browser_required: true`. Browser time is reported as `browser_ms` on
the job: Chrome render time on Go and container workers, and the session time
reported by Browser Run. Older workers may not report it.

## Outputs

- **`body`**: the response body as it came. Text is `body_encoding: "utf8"`;
  PDFs, images and other bytes are `base64`.
- **`document`**: the body plus a prepared `document`: title, description,
  readable `text`, `body_text` with headings, tables and lists, JSON-LD in
  `structured_data`, labelled `links`, a `content_hash` and a `text_hash`.
- **`screenshot`**: a browser screenshot, base64 encoded.
- **`responses`**: the fetch/XHR responses whose URL contains `capture`, each
  with `url`, `status` and `body`.

### Extracting values

With `output: "document"`, `extract` names the values you want, and they come
back as `document.extracted`:

```json
{
  "url": "https://example.com/branch",
  "output": "document",
  "extract": {
    "status": {"selector": "[data-status]", "attribute": "data-status"},
    "notices": {"selector": "main .alert", "all": true},
    "address": {"selector": "address", "text": "lines"},
    "mentions": {"patterns": ["SKU[0-9]{3}"], "all": true},
    "records": {"json_ld_types": ["Product"], "all": true}
  }
}
```

A selector that matches nothing reads `null` (or `[]` with `all`). Every
selector, pattern and keyword is yours; Netscrape has none built in. Use the
same rules in a watch with `compare.on: "extract"` to watch only those fields.

## Results

```json
{
  "url": "https://example.com",
  "final_url": "https://example.com/",
  "status": 200,
  "content_type": "text/html; charset=utf-8",
  "body": "<!doctype html>...",
  "body_encoding": "utf8",
  "rendered": false,
  "challenge": null,
  "duration_ms": 120
}
```

The job's status and the site's status are separate. Reading a page that
answered 404 is a `succeeded` job whose result says `"status": 404`. A job that
failed with a saved result still downloads with HTTP 200; the
`X-Netscrape-Result-Status` header and the job's `response_status` keep the
execution status. `challenge` names a verification screen the read met; see
[Politeness](https://netscrapehq.com/docs/politeness.md#challenges-are-reported-honestly).

`GET /v1/jobs/:id/result` answers `409 result_not_available` before there's a
result, `410 result_expired` after seven days, and `503` if storage is briefly
unavailable.

## Duplicates and idempotency

Submitting the same request while an identical job is still queued or running
returns that job. Once it's finished, the same request makes a new job: this
isn't a response cache.

Send an `Idempotency-Key` header (1–128 letters, digits, `.`, `_`, `:` or `-`)
to make retries safe. The same key with the same request returns the existing
job; with a different request it's `409 idempotency_conflict`. Execution is
at least once, so a crash can repeat a read.

`DELETE /v1/jobs/:id` cancels queued or running work; a finished job answers
`409 job_finished`.

## Discovery

`"type": "discover"` finds the pages on a site that match your rules, within a
budget. You supply the rules: link keywords and patterns to follow, what a
matching page contains, and which paths to include or exclude.

```json
{
  "type": "discover",
  "url": "https://hotel.example/",
  "profile": "custom",
  "signals": {"common_paths": ["/rates"], "exclude_keywords": ["careers"]},
  "link_rules": [
    {"name": "rooms", "url_patterns": ["\\/rooms\\/"], "weight": 60},
    {"name": "rates", "keywords": ["rates", "tariff"], "weight": 40}
  ],
  "content_match": {
    "rules": [{"name": "nightly", "patterns": ["£\\d{2,3} (?:a|per) night"]}],
    "minimum_matches": 1
  },
  "scope": {"exclude_paths": ["/careers"]},
  "budget": {"max_pages": 10, "max_attempts": 24, "max_depth": 2, "max_results": 5, "max_duration_seconds": 300}
}
```

Discovery reads the seed, its links, its sitemaps and the common paths you
name, staying on the seed's host. It always checks robots.txt. Every page it
reads is a child job with its own saved result.

The result lists the selected `pages` (URL, title, score, why each was chosen,
and a `result_url` for its saved read), plus `complete` and
`completion_reason`. A run that ran out of budget succeeds with
`complete: false`; a page missing from a bounded search may still exist. A seed
on a [blocked host](https://netscrapehq.com/docs/politeness.md#blocked-hosts) ends the search at once with
`completion_reason: "host_blocked"`; a candidate page on one is excluded for that
reason and the search goes on.

Budgets: `max_pages` 1–50 (default 10), `max_attempts` 1–200 (default 24),
`max_depth` 0–5 (default 2), `max_results` 1–20 (default 5),
`max_duration_seconds` 30–3600 (default 300).

## Retention

| Data | Kept |
| --- | --- |
| Results: bodies, documents, screenshots, captured responses | 7 days from submission |
| Job records and usage | 90 days |
| Queued work that never ran | Expires after 24 hours |
