# Re-run a job's failed items

> Resets every item with status `failed` back to queued and re-dispatches it; takes no body.

Source: https://docs.spicrawl.com/api-reference/batch/batch-retry

## POST /v1/batch/{batchID}/retry

Operation ID: `batchRetry`. API key scope: `batch`.

Resets every item with status `failed` back to queued and re-dispatches it; takes no body. Succeeded, cancelled
and skipped items are never re-run. If the job was terminal it goes back to `queued` and `finished_at` is
cleared; if it is still running, the reset items join the current run. Item `attempts` is NOT reset.
No items failed → a no-op returning the job unchanged with `items_reset: 0`. A failed item whose hold was already
returned to the monthly allowance holds its price again first; `402` if the allowance cannot cover it, and then
nothing is reset.
Next: poll GET /v1/batch/{batchID} again.

### Example

```bash
curl -X POST "https://api.spicrawl.com/v1/batch/{batchID}/retry" \
  -H "Authorization: Bearer $SPICRAWL_API_KEY"
```

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `batchID` | path | string | yes | The job `id` (26-character ULID as returned). The 32/36-character UUID form of the same id is also accepted. A malformed id and another tenant's id both answer 404. |

### Responses

#### 200

Failed items reset. If `items_dispatched` < `items_reset`, the rest are picked up by the recovery sweep; do not call retry again for them.

Headers: `X-Request-Id`, `X-Credits-Remaining`.

`application/json`.

| Field | Type | Required | Description |
|---|---|---|---|
| `job` | object (`BatchJob`) | yes | The batch job, identical in shape across create, list, get, cancel and close. Poll `status_url` until `status` is terminal (`completed`, `failed`, `cancelled`), then read `results_url` before `results_expire_at`. There is no `credits_held` field: the hold is `estimated_credits`, the spend is `progress.credits_charged`. |
| `items_reset` | integer | yes | Failed items reset to queued. 0 means nothing had failed and nothing changed. |
| `items_dispatched` | integer | yes | Of those, how many reached the dispatch queue now. The rest are recovered by the worker's sweep. |

#### 401

Missing, invalid, revoked or expired key. Not retryable with the same key.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

#### 402

`ERR::LIMIT::QUOTA_EXCEEDED`: the organization is out of credits. Not retryable until credits are added.

Headers: `X-Request-Id`, `X-Credits-Remaining`.

`application/problem+json` (`Problem` schema).

#### 403

The key lacks the scope this route requires (`ERR::AUTH::INSUFFICIENT_SCOPE`), or the action is not permitted.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

#### 404

No such resource for this key's organization.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

#### 500

Internal error. Retryable when `retryable` is true.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

Full OpenAPI spec: https://docs.spicrawl.com/openapi.yaml
