Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ const apiKey = "YOUR-API-KEY";

`client.batch` also exposes `listJobs()`, `deleteJob()`, `stopRun()`, `rerun()`, `listRuns()`, `getRun()`, `deleteRun()`, and `getTaskContent()` (returns the scraped page's raw content as a string, not JSON — the endpoint can return HTML or plain text depending on what the target page served). Scheduling, webhook config, HMAC key rotation, CSV task uploads, and results exports aren't wrapped yet — call the [Batch API](https://docs.zenrows.com) directly for those.

#### Extract in a batch

Set `extract` in the batch params to run tasks through Extract — structured data instead of raw HTML. It works job-wide or per task, and per-task values win on collision.

```js
const job = await client.batch.submitRegular(
[
// Inherits the job-level params below.
{ url: "https://example.com/products", external_id: "p1" },
// Overrides them for this task only.
{ url: "https://example.com/raw", zenrows_params: {} },
],
undefined,
{ zenrowsParams: { extract: "auto" } },
);
```

An Extract task's result carries two keys — `html` (the raw page) and `parsed` (the structured data). It costs the same as a regular task, so `estimateCost` prices it correctly. `extract_fields` is not supported in Batch yet.

The batch client (`ZenRowsBatchClient`) also works standalone, without a `ZenRows` instance — matching the Go and Python SDKs' batch clients:

```javascript
Expand Down
11 changes: 10 additions & 1 deletion src/batch/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,21 @@ export interface WaitForRunOptions {
maxPollInterval?: number;
}

type TaskInput = string | { url: string; external_id?: string; metadata?: Record<string, unknown> };
type TaskInput =
| string
| {
url: string;
external_id?: string;
metadata?: Record<string, unknown>;
/** Per-task scrape params, merged over the job-level `zenrowsParams` (task wins). */
zenrows_params?: Record<string, unknown>;
};

function coerceUrl(item: TaskInput): {
url: string;
external_id?: string;
metadata?: Record<string, unknown>;
zenrows_params?: Record<string, unknown>;
} {
return typeof item === "string" ? { url: item } : item;
}
Expand Down
Loading