# POST /cancel-scrape-job: cancel Google Maps searches

> Cancel one or up to 500 running LocalPipe Google Maps search jobs. Leads already found are kept and stay retrievable.
>
> Part of the LocalPipe API reference: https://www.localpipe.io/docs/cancel-scrape-job (full reference in one file: https://www.localpipe.io/localpipe-api-docs.md, categories CSV: https://www.localpipe.io/localpipe-business-categories.csv)

## POST /cancel-scrape-job

Cancel one or more in-flight Google Maps scrape jobs. Any leads already scraped **remain preserved** in your Business Lists and stay retrievable via `GET /get-scrape-results`. Only jobs still `pending`, `queued`, `running`, `processing`, or `interrupted` are cancellable — jobs already `done`, `failed`, or `cancelled` are returned in `already_terminal` untouched.

### Request

```bash
# Cancel one job
curl -X POST "https://uunrlffonnvmbsstkpze.supabase.co/functions/v1/cancel-scrape-job" \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{"task_id": "uuid-here"}'

# Cancel many at once (up to 500 per call)
curl -X POST "https://uunrlffonnvmbsstkpze.supabase.co/functions/v1/cancel-scrape-job" \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{"task_ids": ["uuid-a", "uuid-b", "uuid-c"]}'
```

### Request Fields

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| task_id | string | Either this or `task_ids` | Single `task_id` returned by `/maps-search`. |
| task_ids | string[] | Either this or `task_id` | Up to 500 `task_id`s to cancel in one call. |

### Response (200 OK)

```json
{
  "success": true,
  "cancelled": ["uuid-a", "uuid-b"],
  "already_terminal": [{ "task_id": "uuid-c", "status": "done" }],
  "not_found": [],
  "message": "Cancelled 2 scrape jobs. Partial results already scraped are preserved in your Business Lists and remain retrievable via GET /get-scrape-results."
}
```

**Notes:**
- Cancellation is asynchronous — the finalizer runs in the background to persist partial results and flip any child work-tiles to `cancelled`. You can immediately re-poll `GET /get-scrape-results?task_id=...` to fetch what was scraped up to the cancel point.
- API keys can only cancel jobs owned by their user (workspace-member keys can cancel jobs they created; unknown/foreign IDs come back in `not_found`).
- Safe to call twice on the same `task_id` — the second call returns it in `already_terminal` with `status: "cancelled"`.
