# Run many runs again

**POST** `/api/runs/rerun`

Runs up to 200 runs again, in the order you send them.

Needs [an API token](https://docs.gorunner.io/api/authentication#scopes) with the **Run** permission for workflows (`workflow:run`).

## Parameters

### Headers

- `Idempotency-Key` · Optional · string: Up to 255 characters. The same request with the same key within 24 hours answers the first result again, instead of acting twice.

### Body

- `ids` · Required · array of strings: Up to 200 run IDs, handled in the order sent. Repeats are taken once.

## One by one

Each ID is handled as [Run a run again](https://docs.gorunner.io/api/runs/rerun-run). A run whose retry already worked or is still going is left out: `ALREADY_RETRIED`. Once the organization’s cap of waiting runs refuses one, the rest aren’t started. A workflow’s own limit (runs at once set to **Refuse**, or its cap of waiting runs) skips only that workflow’s later IDs.

An ID from another workspace answers `NOT_FOUND` in `results` and isn’t touched.

## Responses

- 200 OK

  Each ID’s answer in `results`: `runId` when it started, else `code` and `message`.

- 400 `VALIDATION_ERROR`

  The body isn’t `{"ids": […]}`, or has no IDs or more than 200.

- 403 `FORBIDDEN`

  The token lacks the **Run** permission for workflows.

- 403 `FEATURE_OFF`

  A token made inside a partner’s product, where Run again is switched off.

- 403 `ACCOUNT_SUSPENDED`

  The workspace’s account is suspended. Nothing starts until it is resumed.

- 409 `ACCOUNT_DELETED`

  The workspace’s account was deleted.

- 409 `CONFLICT`

  A request with this `Idempotency-Key` is still in progress.

- 422 `VALIDATION_ERROR`

  This `Idempotency-Key` was already used with a different request.

- 500 `INTERNAL_ERROR`

  A read or write failed. Try again.

- 503 `STATE_UNAVAILABLE`

  The account’s state couldn’t be read. Nothing started. Try again.

Any call can also answer: [`401 UNAUTHORIZED`](https://docs.gorunner.io/errors#UNAUTHORIZED) · [`401 TOKEN_ENDED`](https://docs.gorunner.io/errors#TOKEN_ENDED) · [`403 TOKEN_SURFACE_OFF`](https://docs.gorunner.io/errors#TOKEN_SURFACE_OFF) · [`403 EMBED_NOT_ALLOWED`](https://docs.gorunner.io/errors#EMBED_NOT_ALLOWED) · [`403 EMBED_NOT_AVAILABLE`](https://docs.gorunner.io/errors#EMBED_NOT_AVAILABLE) · [`413 PAYLOAD_TOO_LARGE`](https://docs.gorunner.io/errors#PAYLOAD_TOO_LARGE) · [`415 INVALID_CONTENT_TYPE`](https://docs.gorunner.io/errors#INVALID_CONTENT_TYPE) · [`429 RATE_LIMITED`](https://docs.gorunner.io/errors#RATE_LIMITED) · [`503 PAUSED`](https://docs.gorunner.io/errors#PAUSED) · [`503 BUSY`](https://docs.gorunner.io/errors#BUSY) · [`503 SERVICE_UNAVAILABLE`](https://docs.gorunner.io/errors#SERVICE_UNAVAILABLE). See [Errors](https://docs.gorunner.io/api/errors#by-status).

Request

**curl**

```bash
GORUNNER="https://api.gorunner.io"
GORUNNER_TOKEN="grt_…"  # needs Run for workflows

curl -X POST "$GORUNNER/api/runs/rerun" \
  -H "Authorization: Bearer $GORUNNER_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "ids": [
      "8f0c41d2-6b7e-4c1a-9d3f-2a5b7c9e1f04",
      "1d7f3b9e-2c4a-4e6b-8d0f-5a3c9e1b7d26"
    ]
  }'
```

**JavaScript**

```js
const GORUNNER = "https://api.gorunner.io";
const TOKEN = process.env.GORUNNER_TOKEN;

const res = await fetch(`${GORUNNER}/api/runs/rerun`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${TOKEN}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    ids: [
      "8f0c41d2-6b7e-4c1a-9d3f-2a5b7c9e1f04",
      "1d7f3b9e-2c4a-4e6b-8d0f-5a3c9e1b7d26",
    ],
  }),
});
const { data } = await res.json();
```

**Python**

```python
import os, uuid, requests

GORUNNER = "https://api.gorunner.io"
TOKEN = os.environ["GORUNNER_TOKEN"]

res = requests.post(
    f"{GORUNNER}/api/runs/rerun",
    headers={
        "Authorization": f"Bearer {TOKEN}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
      "ids": [
        "8f0c41d2-6b7e-4c1a-9d3f-2a5b7c9e1f04",
        "1d7f3b9e-2c4a-4e6b-8d0f-5a3c9e1b7d26",
      ],
    },
)
data = res.json()["data"]
```

Response · 200 OK

```json
{
  "data": {
    "results": [
      {
        "id": "8f0c41d2-6b7e-4c1a-9d3f-2a5b7c9e1f04",
        "ok": true,
        "runId": "4b6d8f0a-1c3e-4a5b-9d7f-2e4a6c8b0d13"
      },
      {
        "id": "1d7f3b9e-2c4a-4e6b-8d0f-5a3c9e1b7d26",
        "ok": false,
        "code": "ALREADY_RETRIED",
        "message": "Its retry already worked."
      }
    ],
    "done": 1,
    "refused": 1
  }
}
```

**Every field**

### Body

- `ids` · Required · array of strings: Run ids, in the order to act on them (send oldest first). Duplicates are taken once.

### Response · 200 OK

- `data` · object
  - `results` · array of objects: Each id’s answer, in the order given; ids that are not UUIDs come last.
    - `id` · string
    - `ok` · boolean
    - `runId` · UUID: Run again: the new run.
    - `status` · string: Cancel: the run’s status now (`cancelled`, `cancelling`, or its finished status).
    - `cancelled` · boolean: Cancel: whether this call stopped it.
    - `code` · string: Why it was refused: NOT_FOUND, ALREADY_RETRIED, RUN_NOT_FINISHED, WORKFLOW_NOT_LIVE, or the Run button’s own code; for Cancel, the cancel’s own code (such as `UNAVAILABLE`).
    - `message` · string
  - `done` · integer: Ids this call acted on: a run started, or a run stopped. A finished run left as it is (`ok: true, cancelled: false`) is counted neither here nor in `refused`.
  - `refused` · integer: Ids answered `ok: false`.

Related: [Run a run again](https://docs.gorunner.io/api/runs/rerun-run) · [Cancel many runs](https://docs.gorunner.io/api/runs/cancel-runs-bulk)

Source: https://docs.gorunner.io/api/runs/rerun-runs-bulk
