## Change an automation (desk:admin, or a maintainer of the space)

`PATCH /api/desk/v1/automations/{id}`

Module: Desk · operationId: `patchDeskAutomation` · Tag: Automation · Auth: access token (`Authorization: Bearer <accessToken>`)

Scope `tenant`: `desk:admin`. Scope `space:<id>`: `desk:admin` or a maintainer of the space – the same people who manage the flows scoped to the space; others get 403. Changes what is set: the definition (`yaml`; key and name follow it), `enabled`, `blocking`. `version` is required (409 `version_conflict`). Enabling needs a definition without errors (422 `invalid_definition` with `details.diagnostics`); a definition saved with errors switches the automation off. A key another automation of the scope has is 409 `key_taken`.

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `scope` | query | string | yes | Whose automations: `tenant` (every space) or `space:<space id>` |
| `id` | path | string (uuid) | yes |  |

### Request body

`application/json` (required)

- `version` (integer, required): The version the caller read
- `blocking` (boolean): Whether the automation may refuse the change it reacts to
- `enabled` (boolean): Switch the automation on or off (on needs a definition without errors)
- `yaml` (string): The new definition

Example:

```json
{
  "enabled": false,
  "version": 1
}
```

### Responses

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

Fields of the 200 answer:

- `blocking` (boolean, required): true: a failure of the automation refuses the change that triggered it (422 `automation_blocked`); false (default): the failure is logged and the change is kept
- `createdAt` (string (date-time), required): When the automation was created
- `createdBy` (string, required): E-mail of who created it
- `description` (string, required): The description of the definition
- `enabled` (boolean, required): Only an enabled automation with a valid definition runs
- `events` (array of string, required): The event types its triggers listen to
- `id` (string (uuid), required): Id of the automation
- `key` (string, required): The key of the definition, unique per scope
- `manual` (boolean, required): Whether the definition has a manual trigger
- `name` (string, required): The name of the definition (the actor name of the automation's changes)
- `position` (integer, required): Automations that listen to the same event run in position order
- `scope` (string, required): What the automation belongs to: `tenant` or `space:<space id>`
- `updatedAt` (string (date-time), required): When the automation was last changed
- `updatedBy` (string, required): E-mail of who changed it last
- `valid` (boolean, required): The definition had no error when it was saved; a draft with errors (`false`) cannot be enabled
- `version` (integer, required): Name it when changing or deleting the automation
- `yaml` (string, required): The definition (YAML of the flow language)
- `lastRun` (AutomationRun): One execution of an automation in its log.
  - `automationId` (string (uuid), required): Automation that ran
  - `createdAt` (string (date-time), required): When the run happened
  - `depth` (integer, required): 1 when a person's (or another service's) change started it, n when automations started each other
  - `durationMs` (integer, required): Duration of the run in milliseconds
  - `id` (string (uuid), required): Id of the run
  - `outcome` (string, required): skipped: a limit stopped it (too many automations for one event) (one of `succeeded`, `failed`, `skipped`)
  - `steps` (integer, required): The number of nodes that ran
  - `triggerKind` (string, required): event: started by an event; manual: started by a person on a ticket (one of `event`, `manual`)
  - `version` (integer, required): The version of the automation that ran
  - `actorKind` (string): Who made the triggering change (person, integration, assistant, automation, system, scm)
  - `errorCode` (string): Failed runs: the stable code, e.g. `transition_not_allowed`, `invalid`, `out_of_scope`, `expression`, `invalid_definition`, `action_failed`
  - `errorMessage` (string): Why the run failed (only on failure)
  - `event` (string): The event type that started it
  - `node` (string): The id of the node that failed
  - `startedBy` (string): The person or actor behind the triggering change
  - `subject` (string): What the event was about: the item's id

Example 200 answer:

```json
{
  "blocking": false,
  "createdAt": "2026-10-05T09:00:00Z",
  "createdBy": "elias.gruber@muster-it.example",
  "description": "Eine kritische Störung bekommt sofort das Team Service Desk als mitarbeitendes Team.",
  "enabled": true,
  "events": [
    "desk.item.created"
  ],
  "id": "8c5d6e7f-9a0b-4c1d-8e3f-5a6b7c8d9e01",
  "key": "kritische-stoerung-1st-level",
  "lastRun": {
    "actorKind": "person",
    "automationId": "8c5d6e7f-9a0b-4c1d-8e3f-5a6b7c8d9e01",
    "createdAt": "2026-11-17T12:05:01Z",
    "depth": 1,
    "durationMs": 21,
    "event": "desk.item.created",
    "id": "9e6f7a8b-0c1d-4e2f-9a4b-6c7d8e9f0a01",
    "outcome": "succeeded",
    "startedBy": "elias.gruber@muster-it.example",
    "steps": 1,
    "subject": "4a1b2c3d-5e6f-4a7b-8c9d-1e2f3a4b5c02",
    "triggerKind": "event",
    "version": 1
  },
  "manual": false,
  "name": "Kritische Störung an den Service Desk",
  "position": 1,
  "scope": "tenant",
  "updatedAt": "2026-10-05T09:00:00Z",
  "updatedBy": "elias.gruber@muster-it.example",
  "valid": true,
  "version": 1,
  "yaml": "schemaVersion: 1\nkey: kritische-stoerung-1st-level\nname: Kritische Störung an den Service Desk\ndescription: Eine kritische Störung bekommt sofort das Team Service Desk als mitarbeitendes Team.\ntriggers:\n  - { id: neu, kind: event, event: desk.item.created, filter: 'trigger.data.typeKey == \"stoerung\" \u0026\u0026 trigger.data.priority == \"kritisch\"' }\nnodes:\n  zuweisen:\n    kind: action\n    name: Team Service Desk hinzufügen\n    action: desk.item.assign\n    params: { ref: \"{{ trigger.data.itemId }}\", team: first-level, teamRole: collaborating }\nedges:\n  - neu -\u003e zuweisen\n"
}
```

### Example request

```bash
curl -X PATCH 'https://api.mbcom.cloud/api/desk/v1/automations/3f2b8c1e-7d4a-4e9b-9c2a-5b1d6e8f0a12?scope=tenant' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"enabled":false,"version":1}'
```
