# Batches

`POST https://api.serpwiz.com/v1/batches`

Queue up to **10,000** Google Search or Google Maps queries in one request. They run in the background, and you download all the results as one **JSONL** or **CSV** file. You can also create batches without code in your [dashboard](https://serpwiz.com/dashboard/batches), pasting searches or loading a CSV.

**Billing is the same as single requests:** each query costs 1 query when it succeeds, and failed queries are free. Creating, checking and downloading a batch costs nothing. Your batches run one query at a time and give way to live traffic, so your API calls stay fast and a large batch takes a while (roughly 1–5 seconds per query): watch its progress or set a webhook.

## Create a batch

```bash
curl -X POST "https://api.serpwiz.com/v1/batches" \
  -H "X-API-Key: $SERPWIZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "endpoint": "google/maps",
    "name": "Florida dentists",
    "params": {"num": 200, "popular_times": true},
    "queries": [
      "dentists in miami",
      "dentists in tampa",
      {"q": "dentists", "location": "Orlando, FL", "num": 50}
    ],
    "webhook_url": "https://example.com/hooks/serpwiz"
  }'
```

| Field | Description |
|---|---|
| `endpoint` | `google/search` or `google/maps`. Required. |
| `queries` | Up to 10,000 items. Each is a search string (sent as `q`) or an object of parameters, exactly as for [Google Search](/docs/google-search) or [Google Maps](/docs/google-maps). Required. |
| `params` | Parameters applied to every query, e.g. `{"num": 200, "gl": "us"}`. A query's own parameters win. Optional. |
| `name` | A label for the dashboard (max 120 characters). Optional. |
| `webhook_url` | An `https://` URL we `POST` to when the batch finishes. Optional. |

Every query is checked before the batch starts, so a bad parameter returns `400` straight away (for example `Query 12: \`num\` must be between 1 and 200.`) and nothing runs. The response is `201` with the batch object below. You can have up to 5 unfinished batches at once.

## Check progress

`GET https://api.serpwiz.com/v1/batches/{id}`

```json
{
  "id": "b_06dfa9920e9cae",
  "name": "Florida dentists",
  "endpoint": "google/maps",
  "status": "done",
  "pause_reason": null,
  "total": 3,
  "completed": 3,
  "succeeded": 3,
  "failed": 0,
  "charged": 3,
  "results_ready": 3,
  "created_at": "2026-12-06T10:16:05+00:00",
  "started_at": "2026-12-06T10:16:06+00:00",
  "finished_at": "2026-12-06T10:16:30+00:00",
  "expires_at": "2026-12-07T10:16:30+00:00",
  "results": {
    "jsonl": "https://serpwiz.com/batches/b_06dfa9920e9cae/download?format=jsonl&exp=…&sig=…",
    "csv": "https://serpwiz.com/batches/b_06dfa9920e9cae/download?format=csv&exp=…&sig=…",
    "link_expires_in": 3600
  },
  "results_deleted": false
}
```

| `status` | Meaning |
|---|---|
| `running` | Queries are running. `results` already links to everything finished so far. |
| `paused` | Stopped for now. `pause_reason` is `no_credits` when your balance ran out: the batch **resumes by itself** after you top up. |
| `done` | Every query has run. |
| `canceled` | You canceled it. Queries that already ran are charged and their results stay downloadable. |

`GET https://api.serpwiz.com/v1/batches` lists your 50 most recent batches.

## Download results

The `results` links are signed and work for an hour, with no API key, so you can hand them to another tool. Fetch the batch again for fresh links. Both files are gzipped.

- **JSONL** (`.jsonl.gz`): one line per query, `{"index": 0, "params": {…}, "status": 200, "data": {…}}`, where `data` is exactly what the single endpoint returns. A failed query has `"error": {"code", "message"}` instead of `data`. Lines are in the order queries finished, so use `index` (the query's position in your request, from 0) to match them up.
- **CSV** (`.csv.gz`): one row per place (Maps: name, category, address, phone, website, rating, reviews, coordinates, Place ID…) or per organic result (Search: position, title, URL, description), with the query's `index` and search terms on every row.

**Results are deleted 24 hours after the batch finishes.** After that the batch still shows its counts, `results_deleted` is `true` and download links return `410`.

```bash
curl -s "$CSV_LINK" | gunzip > results.csv
```

## Cancel or resume

`POST https://api.serpwiz.com/v1/batches/{id}/cancel` stops a batch. Queries already running finish; the rest are dropped and never charged.

`POST https://api.serpwiz.com/v1/batches/{id}/resume` restarts a paused batch (it also resumes by itself once you have queries again).

## Webhook

When the batch finishes (or is canceled) we `POST` JSON to your `webhook_url`, retrying up to 3 times if your server doesn't answer `2xx`:

```json
{"event": "batch.done", "batch": { …the same object as GET /v1/batches/{id}… }}
```

To be sure a webhook came from us, fetch the batch with your API key before acting on it.

## Errors

Same format as every endpoint (see [Errors](/docs/errors)), plus:

| Status | `code` | What happened |
|---|---|---|
| `400` | `invalid_request` | Bad JSON, an unknown `endpoint`, more than 10,000 queries, or a query with an invalid parameter (the message says which). |
| `402` | `insufficient_credits` | Your balance is empty, so the batch can't start. |
| `404` | `not_found` | No batch with that ID on your account. |
| `429` | `too_many_batches` | You already have 5 unfinished batches. |
