# Cancel a run

**POST** `/api/embed/v1/accounts/{accountId}/runs/{runId}/cancel`

Stops one of an account’s runs, as Cancel on the Runs page does.

Needs a partner key: `Authorization: Bearer gre_…`, from [Platform › Partner keys](https://docs.gorunner.io/embed/platform-screens#partner-keys). Call it from your server only.

Embed · Self-hosted with an Embed license

## Parameters

### Path

- `accountId` · Required · string: Your ID for the customer’s account: 1 to 255 bytes of UTF-8, case-sensitive. URL-encode it: it may contain `/`.
- `runId` · Required · UUID: The run’s ID.

### Headers

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

## What happens

A run waiting in line leaves it and never runs. A held run is settled. A running one is asked to stop and reads `cancelling` until its worker has. A finished run is left as it is: `cancelled: false`, with its status.

Only runs this API lists can be reached. The account’s audit log gets an `embed.run.cancel` row.

## Responses

- 200 OK

  The run as it stands now.

- 400 `VALIDATION_ERROR`

  The account ID isn’t allowed as written. `details.field` names it.

- 404 `NOT_FOUND`

  No such account, or no such run in it.

- 409 `ACCOUNT_DELETED`

  The account is deleted. Restore it first, within 30 days.

- 409 `CONFLICT`

  A request with this `Idempotency-Key` is still running. Retry shortly.

- 422 `VALIDATION_ERROR`

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

- 500 `INTERNAL_ERROR`

  Something failed on the installation’s side. Try again.

Any call can also answer: [`401 UNAUTHORIZED`](https://docs.gorunner.io/errors#UNAUTHORIZED) · [`403 EMBED_NOT_LICENSED`](https://docs.gorunner.io/errors#EMBED_NOT_LICENSED) · [`403 IP_NOT_ALLOWED`](https://docs.gorunner.io/errors#IP_NOT_ALLOWED) · [`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). See [Errors](https://docs.gorunner.io/embed/api#errors).

Request

**curl**

```bash
GORUNNER="https://automations.example.com"
GORUNNER_EMBED_KEY="YOUR_PARTNER_KEY"  # gre_…
ACCOUNT_ID="acct-bakery"
RUN_ID="your-run-id"

URL="$GORUNNER/api/embed/v1/accounts/$ACCOUNT_ID/"
URL="${URL}runs/$RUN_ID/cancel"
curl -X POST "$URL" \
  -H "Authorization: Bearer $GORUNNER_EMBED_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

**JavaScript**

```js
const GORUNNER = "https://automations.example.com";
const KEY = process.env.GORUNNER_EMBED_KEY; // gre_…
const ACCOUNT_ID = encodeURIComponent("acct-bakery");
const RUN_ID = encodeURIComponent("your-run-id");

const res = await fetch(
  `${GORUNNER}/api/embed/v1/accounts/` +
    `${ACCOUNT_ID}/runs/${RUN_ID}/cancel`,
  {
    method: "POST",
    headers: {
        Authorization: `Bearer ${KEY}`,
        "Idempotency-Key": crypto.randomUUID(),
      },
  },
);
const { data } = await res.json();
```

**Python**

```python
import os, uuid, requests
from urllib.parse import quote

GORUNNER = "https://automations.example.com"
KEY = os.environ["GORUNNER_EMBED_KEY"]  # gre_…
ACCOUNT_ID = quote("acct-bakery", safe="")
RUN_ID = quote("your-run-id", safe="")

res = requests.post(
    f"{GORUNNER}/api/embed/v1/accounts/"
    f"{ACCOUNT_ID}/runs/{RUN_ID}/cancel",
    headers={
        "Authorization": f"Bearer {KEY}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
)
data = res.json()["data"]
```

Response · 200 OK

```json
{
  "data": {
    "run": {
      "id": "8f0c41d2-6b7e-4c1a-9d3f-2a5b7c9e1f04",
      "status": "cancelling"
    },
    "cancelled": true
  }
}
```

**Every field**

It takes no body.

### Response · 200 OK

- `data` · object
  - `run` · object
    - `id` · UUID
    - `status` · string: The run’s status now, as EmbedRun says it, or `cancelling` while a running run stops.
  - `cancelled` · boolean: Whether this call stopped it; false for a run that had already finished.

Related: [Cancel a workflow’s waiting runs](https://docs.gorunner.io/embed/api/workflows/cancel-waiting-runs) · [Get a run](https://docs.gorunner.io/embed/api/runs/get-run)

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