# POST /api/v2/automations/{automation}/versions

Save a new version of an automation's flow

- MCP id: automations.versions.store
- Scope: api:write:automations
- Scope: api:write:project_automations
- Scope: api:write:customer_automations
- Permission: automations::update
- Needs the automations feature on your organisation
- Rate cost: 1 unit, write bucket. A write costs the same whatever `view` you ask for.
- Cache-Control: private, no-store

Saves the flow as the automation's next version, which becomes the one that runs, and returns it with a `Location` header.

The flow is checked exactly as the builder checks it, for you and for the owner whose permissions runs use, and a setting a step does not have is refused by name: every problem comes back in one `422`, each at its JSON Pointer, such as `/definition/nodes/3/config/recipients`, and nothing is saved. Read what a step takes at `GET /api/v2/automation-node-types/{slug}`, and check a flow first with `actions/check-flow`. `base_version` is the version your change starts from (`0` for the first save); a newer one answers `409` `stale_version` with `conflict.current_version`. Saving an automation that is switched on needs `while_active: true` (`409` `automation_active` otherwise). Send `{key, unchanged: true}` for a step to keep it exactly as `base_version` has it, and only the steps you change in full; a step without `ui` keeps its position, or a new one gets the trigger's, and the builder lays the flow out again. A secret typed into a step is stored encrypted and only its reference is kept. The declared permission is `automations::update`; for a project or customer automation, the `project_automations` or `customer_automations` permission of the same action applies instead.

## Parameters
- automation (integer, path): The Automation's numeric id. Accepts a soft-deleted record.
- view (string, optional): Which field set to render.
- X-Request-Id (header, optional): A correlation id of your own. It is recorded in our logs next to the server's request id but never returned: the response header always carries the server's id. A value that does not match the pattern is discarded silently, never rejected.
- Idempotency-Key (header, optional): A caller-chosen key that makes this POST safe to retry. Replaying it returns the original response with Idempotency-Replayed: true.

## Request body
- base_version (integer ≥ 0, required): On save, the version number your change starts from; `0` for an automation without a flow yet. When the flow was saved again since, the save is refused with `409` `stale_version` and nothing is kept, so two editors cannot overwrite each other and a retried save cannot save twice.
- definition (object, required): The flow as it is stored and as the builder draws it.
  - nodes (array of any ≤ 100, required)
  - edges (array of object ≤ 300, required)
- while_active (boolean, optional): On save, `true` to save a new version of an automation that is switched on, which takes effect on its next trigger. Without it such a save is refused with `409` `automation_active`.

Unknown keys are refused with `422` validation-failed, naming the key.

## Response 201
- id (integer, required): Unique identifier.
- automation_id (integer, required): The automation whose flow this is.
- version (integer, required): Version number within its automation, counting from 1.
- is_current (boolean, required): Whether this is the version whose flow runs.
- saved_by_id (integer or null, required): Who saved this version. `null` once that user is gone.
- created_at (timestamp (YYYY-MM-DDThh:mm:ssZ) or null, required): When the version was saved.
- definition (object, required, detail only): The flow as it is stored and as the builder draws it.
  - nodes (array of object, required): Every step, the trigger included.
  - edges (array of object, required): The lines between steps, in the order steps on the same lane run.
- outline (array of object, required, detail only): The steps in the order people read the flow, each with what it does and where its lines lead. Lets a reader explain a flow without decoding `definition`.
- automation (Ref or AutomationSummary, required): The automation whose flow this is.
- saved_by (Ref or UserSummary or null, required): Who saved this version.
- links (AutomationVersionLinks, required)
  - self (url, required): The canonical URI of this record.

## Errors
- 403 forbidden-by-policy | insufficient-permission | insufficient-token-scope: Forbidden.
- 409 idempotency-key-in-flight | idempotency-key-reused | state-conflict: Conflict.
- 415 unsupported-media-type: Unsupported media type.
- 422 unprocessable-relationship | validation-failed: Unprocessable content.
- 400 idempotency-key-required | invalid-cursor | invalid-query-parameter | malformed-request | unsupported-parameter: Bad request.
- 401 token-expired | unauthenticated: Unauthenticated.
- 404 endpoint-not-found | resource-not-found: Not found.
- 406 not-acceptable: Not acceptable.
- 429 rate-limit-exceeded: Too many requests.
- 500 internal-error: Server error.
- 503 tenant-unavailable: Service unavailable.

## Example
```bash
curl -X POST \
  'https://<your-url>/api/v2/automations/1/versions' \
  -H 'Authorization: Bearer <token>' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: <key>' \
  -d '{
    "base_version": 0,
    "definition": {
      "nodes": [
        {
          "key": "9d2c1b7e-4f3a-4e8b-a1c6-2b5d8e9f0a11",
          "type": "trigger.record_created",
          "config": {
            "model": "work_item"
          }
        },
        {
          "key": "5a7e3c2d-1b4f-4d9e-8c6a-3f2e1d0b9c88",
          "type": "action.notify",
          "config": {
            "recipients": {
              "fields": [
                "assignee_id"
              ]
            },
            "title": "New work: {{ record.title }}"
          }
        }
      ],
      "edges": [
        {
          "from": "9d2c1b7e-4f3a-4e8b-a1c6-2b5d8e9f0a11",
          "lane": "next",
          "to": "5a7e3c2d-1b4f-4d9e-8c6a-3f2e1d0b9c88"
        }
      ]
    }
  }'
```
