# Cancel Run

Ask a run to stop. A run still waiting to start is cancelled at once and answers status "cancelled". A running run stops at its next checkpoint and then reports status "cancelled". Finished runs are unaffected.

`POST https://connect.mindcloud.co/v2/runs/:runId/cancel`

Permissions: `workflow:run`.

## Parameters

### Path

- `runId` (string, required): The run's id, from Run a Workflow or List Runs.

### Headers

- `X-Company-Id` (string): Optional. The id of the organization to act in. Leave it out to act in the API key's own organization. A key can also act in its child organizations, and, with "Use this key across all of your organizations" on, in every organization its creator can open in the app. List them with GET /v2/companies. Every response's X-Company-Id header names the organization it acted in. See [Organizations](https://mindcloud.co/docs/api/rest/introduction/organizations).

## Example request

```bash
curl --request POST \
  --url 'https://connect.mindcloud.co/v2/runs/Rm4pQ7sJt1Ve/cancel' \
  --header 'Authorization: Bearer $MINDCLOUD_API_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{}'
```

## Response fields

- `id` (string): The run that was asked to stop.
- `status` (string): "cancelled" when the run had not started and was cancelled at once; otherwise the run status when the cancellation was requested, and the run reports "cancelled" once it stops.

## Example response

```json
{
  "success": true,
  "data": {
    "id": "Rm4pQ7sJt1Ve",
    "status": "running"
  }
}
```

## Errors

- 403 Missing permission (API_KEY_PERMISSION_DENIED, API_KEY_CREATOR_INACTIVE): `FORBIDDEN` / `API_KEY_PERMISSION_DENIED` "This API key needs the workflow:run permission for this operation."
- 404 Run not found: `NOT_FOUND` "Run "Rm4pQ7sJt1Ve" was not found."
- 409 Run already finished: `CONFLICT` / `RUN_NOT_CANCELLABLE` "Run "Rm4pQ7sJt1Ve" already finished with status "finished" and cannot be cancelled."
