# PATCH /api/v2/automations/{automation}

Update an automation

- MCP id: automations.update
- 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

Changes an automation's name, description or scope; absent keys stay as they are.

Its flow is saved as a new version instead, with `POST /api/v2/automations/{automation}/versions`, and it is switched on and off with its actions. Moving it to another scope takes the right to make automations there, and its flow is checked again where it moves to: a flow that would not save there is refused with a `422` at `/context_type` and nothing changes. Sending a new `context_type` without a `context_id` moves it to every project or customer. Only plnnrly support may change `owner_id`. Send `If-Match` with the `ETag` from your last read to detect a concurrent edit, which answers `412`. 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.
- trashed (string, optional): Whether soft-deleted rows are included.
- 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.
- If-Match (header, optional): The ETag a write is conditional on. A stale validator is 412 precondition-failed.

## Request body
- name (string ≤ 255, required): Name as shown in the automations list.
- description (string or null ≤ 2000, optional): What the automation is for, in its makers' words.
- context_type (string or null, optional): What the automation belongs to. `null` is the whole organisation. With a type, `context_id` names the one project or customer, or is `null` for every one of them. The scope decides which permissions apply: `automations`, `project_automations` or `customer_automations`.
- context_id (integer or null, optional): The one project or customer the automation belongs to. `null` with a `context_type` means every project or every customer.
- owner_id (integer or null, optional): The person who made the automation. Its runs use their permissions, so a step they may not do is refused when the flow is saved. `null` once that user is gone. It is whoever creates the automation and never changes, except for plnnrly support's own account, which must name a real person here when it creates or changes one.

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

## Response 200
- id (integer, required): Unique identifier.
- name (string ≤ 255, required): Name as shown in the automations list.
- description (string or null, required, multiline): What the automation is for, in its makers' words.
- context_type (string or null, required): What the automation belongs to. `null` is the whole organisation. With a type, `context_id` names the one project or customer, or is `null` for every one of them. The scope decides which permissions apply: `automations`, `project_automations` or `customer_automations`.
- context_id (integer or null, required): The one project or customer the automation belongs to. `null` with a `context_type` means every project or every customer.
- owner_id (integer or null, required): The person who made the automation. Its runs use their permissions, so a step they may not do is refused when the flow is saved. `null` once that user is gone. It is whoever creates the automation and never changes, except for plnnrly support's own account, which must name a real person here when it creates or changes one.
- owner_requires_replacement (boolean, required): Whether the owner is plnnrly support's own account. Such an automation cannot be saved or switched on until a real person is named as its owner.
- is_active (boolean, required, server-assigned): Whether the automation is switched on. A new automation is always off.
- is_runnable (boolean, required): Whether triggers start runs right now: switched on, not paused and not deleted.
- paused_reason (string or null, required): Why plnnrly paused the automation, such as a step that kept failing. `null` while it is not paused. Switching it on again clears it. Never names record data.
- current_version_id (integer or null, required): The version whose flow runs. `null` until a flow is first saved.
- trigger_type (string or null ≤ 255, required, server-assigned): The step type of the flow's trigger, such as `trigger.record_created`, taken from the current version. See `GET /api/v2/automation-node-types`.
- trigger_record_type (string or null ≤ 255, required, server-assigned): The record type the trigger starts on, such as `work_item`, or `null` for a trigger without a record, such as a schedule.
- trigger_events (array of string, required): The record events the trigger starts on. Empty for a trigger that does not start on record events, such as a schedule or a date being reached.
- next_run_at (timestamp (YYYY-MM-DDThh:mm:ssZ) or null, required): When a schedule trigger next starts a run. `null` for other triggers.
- last_run_at (timestamp (YYYY-MM-DDThh:mm:ssZ) or null, required): When the automation last started a run.
- runs_count (integer, required): How many live runs the automation has started, as counted for the organisation's usage. Test runs and runs that were skipped are not counted.
- template_key (string or null ≤ 100, required): The template the automation was made from, `null` when it was built from scratch. See `GET /api/v2/automation-templates`. Send it on create to start from that template: its flow is saved as version 1, with the answers in `template_answers` in their places.
- manual_inputs (array of object, required, detail only): What a person fills in when they start the automation by hand, as its trigger declares it. Empty for an automation that is not started by hand.
- webhook_url (string or null, required): The address other systems send requests to, for an automation whose trigger receives webhooks; `null` otherwise. Requests must also prove they know the automation's secret, which this API never returns.
- updated_by_id (integer or null, required): Who last saved the automation's flow or settings.
- created_at (timestamp (YYYY-MM-DDThh:mm:ssZ), required): Creation timestamp.
- updated_at (timestamp (YYYY-MM-DDThh:mm:ssZ), required): Last-write timestamp; use for incremental sync.
- deleted_at (timestamp (YYYY-MM-DDThh:mm:ssZ) or null, required): Soft-delete timestamp, `null` while live. A deleted automation starts no runs.
- owner (Ref or UserSummary or null, required): The person who made the automation.
- updated_by (Ref or UserSummary or null, required): Who last saved the automation.
- current_version (Ref or AutomationVersionSummary or null, required): The version whose flow runs.
- versions_count (integer ≥ 0, required): Number of saved versions of the flow.
- links (AutomationLinks, required)
  - self (url, required): The canonical URI of this record.
  - versions (url, required): Every saved version of the flow, newest first.
  - runs (url, required): The automation's runs, newest first.

## Errors
- 403 forbidden-by-policy | insufficient-permission | insufficient-token-scope: Forbidden.
- 412 precondition-failed: Precondition failed.
- 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 PATCH \
  'https://<your-url>/api/v2/automations/1' \
  -H 'Authorization: Bearer <token>' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'If-Match: *' \
  -d '{
    "name": "Tell assignees about urgent work (v2)"
  }'
```
