# Cancel waiting runs

**POST** `/api/workflows/{id}/runs/cancel-waiting`

Cancels all of a workflow’s runs waiting in line, in one step.

Needs [an API token](https://docs.gorunner.io/api/authentication#scopes) with the **Cancel and delete** permission for runs (`run:manage`).

## Parameters

### Path

- `id` · Required · UUID: The workflow’s ID.

## What it takes, and what it leaves

It takes production and test runs that haven’t started. Each becomes `cancelled` with the error “Cancelled by user” and no duration.

Runs that started are left: running, held, or carrying on after an answer. [Cancel them one by one](https://docs.gorunner.io/api/runs/cancel-run). A run a worker takes at that moment is either cancelled or runs, never both.

The audit log gets one `run.cancel` row with the count, or none when nothing waited. It takes no body.

## Responses

- 200 OK

  How many were cancelled; 0 when none waited.

- 400 `VALIDATION_ERROR`

  `id` isn’t a UUID.

- 403 `FORBIDDEN`

  The token lacks the **Cancel and delete** permission for runs.

- 404 `NOT_FOUND`

  No workflow with this ID in the token’s workspace.

- 500 `INTERNAL_ERROR`

  Nothing was cancelled. 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 FEATURE_OFF`](https://docs.gorunner.io/errors#FEATURE_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) · [`403 ACCOUNT_SUSPENDED`](https://docs.gorunner.io/errors#ACCOUNT_SUSPENDED) · [`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 BUSY`](https://docs.gorunner.io/errors#BUSY) · [`503 PAUSED`](https://docs.gorunner.io/errors#PAUSED) · [`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 Cancel and delete for runs
WORKFLOW_ID="your-workflow-id"

URL="$GORUNNER/api/workflows/$WORKFLOW_ID/runs/"
URL="${URL}cancel-waiting"
curl -X POST "$URL" \
  -H "Authorization: Bearer $GORUNNER_TOKEN"
```

**JavaScript**

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

const res = await fetch(
  `${GORUNNER}/api/workflows/${WORKFLOW_ID}/` +
    `runs/cancel-waiting`,
  {
    method: "POST",
    headers: { Authorization: `Bearer ${TOKEN}` },
  },
);
const { data } = await res.json();
```

**Python**

```python
import os, requests

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

res = requests.post(
    f"{GORUNNER}/api/workflows/{WORKFLOW_ID}/runs/"
    f"cancel-waiting",
    headers={"Authorization": f"Bearer {TOKEN}"},
)
data = res.json()["data"]
```

Response · 200 OK

```json
{
  "data": {
    "cancelled": 5
  }
}
```

**Every field**

It takes no body.

### Response · 200 OK

- `data` · object
  - `cancelled` · integer: The runs this call took out of the line and settled `cancelled`.

Related: [Count a workflow’s waiting runs](https://docs.gorunner.io/api/runs/count-waiting-runs) · [List waiting runs](https://docs.gorunner.io/api/runs/list-waiting-runs) · [Limit runs at once](https://docs.gorunner.io/build/runs-at-once)

Source: https://docs.gorunner.io/api/runs/cancel-waiting-runs
