## Cancel a running workflow instance (workflow:admin)

`POST /api/workflow/v1/tasks/{instanceId}/cancel`

Module: Workflow · operationId: `cancelInstance` · Tag: Instances · Auth: access token (`Authorization: Bearer <accessToken>`)

Ends the instance as `CANCELLED` (also a pending start) and writes the state to trade, which
releases the transaction. An instance that has already ended answers `409 invalid_state`. The body is optional.

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `instanceId` | path | string (uuid) | yes | Instance id (`guid`) |

### Request body

`application/json`

- `reason` (string): Stored as the comment of the history entry (max length 1000)

Example:

```json
{
  "reason": "Vorgang wurde storniert"
}
```

### Responses

- **200** Cancelled (`application/json`)
- **400** Error (`application/json`)
- **401** Missing or invalid token (`unauthorized`) (`application/json`)
- **403** Error (`application/json`)
- **404** Error (`application/json`)
- **409** Error (`application/json`)
- **500** Error (`application/json`)

Fields of the 200 answer:

- `status` (string): Always `ok`

Example 200 answer:

```json
{
  "status": "ok"
}
```

### Example request

```bash
curl -X POST 'https://api.mbcom.cloud/api/workflow/v1/tasks/3f9c2a1e-8b7d-4c6e-a5f4-1d2b3c4e5f60/cancel' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"reason":"Vorgang wurde storniert"}'
```
