## Change a workflow (tenant:forge:write and maintainer, or tenant:forge:admin)

`PATCH /api/forge/v1/projects/{key}/workflows/{id}`

Module: Forge · operationId: `patchForgeWorkflow` · Tag: Configuration · Auth: access token (`Authorization: Bearer <accessToken>`)

Same permission as creating. `version` is required (409 `version_conflict`); keys never change. Dropping a status that items of the workflow's types sit on is 409 `in_use` with `details.counts`.

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `key` | path | string | yes | Project key (e.g. APP) |
| `id` | path | string (uuid) | yes |  |

### Request body

`application/json` (required)

- `key` (string): Create: workflow key; fixed afterwards
- `name` (string): Display name (max length 60)
- `statusIds` (array of string (uuid)): Statuses of the workflow (at least one); replaces the list on PATCH
- `transitions` (array of Transition): Allowed moves; empty = free movement; replaces the list on PATCH
  - `fromStatusId` (string (uuid), required): Status the move starts from
  - `toStatusId` (string (uuid), required): Status the move leads to
- `version` (integer): PATCH: the version the change is based on

Example:

```json
{
  "transitions": [
    {
      "fromStatusId": "5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f03",
      "toStatusId": "5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f04"
    },
    {
      "fromStatusId": "5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f04",
      "toStatusId": "5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f05"
    },
    {
      "fromStatusId": "5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f04",
      "toStatusId": "5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f03"
    }
  ],
  "version": 1
}
```

### Responses

- **200** Changed (`application/json`)
- **400** Error (`application/json`)
- **403** Error (`application/json`)
- **404** Error (`application/json`)
- **409** Error (`application/json`)

Fields of the 200 answer:

- `id` (string (uuid), required): Workflow id
- `key` (string, required): Workflow key; never changes
- `name` (string, required): Display name
- `position` (integer, required): Order in the configuration
- `statusIds` (array of string (uuid), required): Statuses of the workflow
- `transitions` (array of Transition, required): Empty = free movement among the statuses
  - `fromStatusId` (string (uuid), required): Status the move starts from
  - `toStatusId` (string (uuid), required): Status the move leads to
- `version` (integer, required): Optimistic-locking version; send it with PATCH

Example 200 answer:

```json
{
  "id": "6e2f3a4b-5c6d-4e7f-9a8b-2c3d4e5f6a01",
  "key": "standard",
  "name": "Standard",
  "position": 0,
  "statusIds": [
    "5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f01",
    "5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f02",
    "5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f03",
    "5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f04",
    "5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f05",
    "5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f06"
  ],
  "transitions": [],
  "version": 1
}
```

### Example request

```bash
curl -X PATCH 'https://api.mbcom.cloud/api/forge/v1/projects/string/workflows/3f2b8c1e-7d4a-4e9b-9c2a-5b1d6e8f0a12' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"transitions":[{"fromStatusId":"5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f03","toStatusId":"5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f04"},{"fromStatusId":"5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f04","toStatusId":"5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f05"},{"fromStatusId":"5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f04","toStatusId":"5d1e2f3a-4b5c-4d6e-8f7a-1b2c3d4e5f03"}],"version":1}'
```
