> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackshift.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Automations API and CLI

> Create, run, approve and inspect automations under /api/v1/automations, with the JavaScript and Go SDKs, or with stackshift automations.

> [!TIP]
>
> **Live.** This area is documented as current, user-reliable behavior.

## Goal

Manage automations from code or a terminal.

## Prerequisites

* An API token or the signed-in CLI. Add team\_id for a team’s automations.

## Workflow

**Step 1**

List with stackshift automations list or GET /api/v1/automations.

**Step 2**

Run with stackshift automations run AUTOMATION or POST /api/v1/automations/\{id}/runs.

**Step 3**

Approve with stackshift automations approve RUN --data '\{"decision":"approved"}'.

## CLI

```bash stackshift automations theme={null}
stackshift automations list
stackshift automations create --file automation.json
stackshift automations get AUTOMATION
stackshift automations update AUTOMATION --file automation.json
stackshift automations enable AUTOMATION
stackshift automations disable AUTOMATION
stackshift automations delete AUTOMATION
stackshift automations access AUTOMATION --data '{"actions":["database.restart"]}'
stackshift automations run AUTOMATION
stackshift automations runs
stackshift automations run-get RUN
stackshift automations run-cancel RUN
stackshift automations run-again RUN
stackshift automations approve RUN --data '{"decision":"approved"}'
stackshift automations actions
stackshift automations templates
```

## API

* GET, POST /api/v1/automations; GET, PUT, DELETE /api/v1/automations/\{id}. PUT takes name, description, definition and expected\_revision.
* POST /\{id}/enable, /\{id}/disable, /\{id}/runs (test: true for a test run), /\{id}/rerun-failed and /\{id}/webhook (returns url and secret). PUT /\{id}/access with actions. PUT and DELETE /\{id}/secrets/\{name}.
* GET /runs (filter by automation\_id and status), GET /runs/\{runId}, POST /runs/\{runId}/cancel, /runs/\{runId}/rerun and /runs/\{runId}/approval.
* GET /actions lists every action with its tier and whether it is available. GET /templates?category=media lists the Media templates.

## SDKs

The JavaScript SDK has stackshift.automations and the Go SDK has client.Automations, with one method per route: list, create, get, save, delete, enable, disable, setAccess, run (StartRun in Go), rerunFailed, putSecret, deleteSecret, rotateWebhook, actions, templates, previewTrigger, listRuns, getRun, cancelRun, rerun and decide.

A save that breaks a rule fails with code automation\_invalid, and the error details list each issue with its node\_id.

```ts Create, turn on and test an automation theme={null}
const automation = await stackshift.automations.create({ team_id: 'team_123', name: 'Redeploy on failure' })
await stackshift.automations.save(automation.id, {
  name: automation.name,
  expected_revision: automation.revision,
  definition: {
    version: 1,
    nodes: [
      { id: 'trigger', type: 'trigger.event', config: { event_types: ['deploy.failed'] } },
      { id: 'redeploy', type: 'platform.action', action: 'projects.redeploy', config: { project_id: 'proj_123' } },
    ],
    edges: [{ id: 'e1', source: 'trigger', target: 'redeploy' }],
  },
})
await stackshift.automations.enable(automation.id)
const run = await stackshift.automations.run(automation.id, { test: true })
const detail = await stackshift.automations.getRun(run.id)
```

```go Go theme={null}
automation, err := client.Automations.Create(ctx, stackshift.CreateAutomationInput{TeamID: "team_123", Name: "Redeploy on failure"})
if err != nil {
  return err
}
_, err = client.Automations.Save(ctx, automation.ID, stackshift.SaveAutomationInput{
  Name:             automation.Name,
  ExpectedRevision: automation.Revision,
  Definition: stackshift.AutomationDefinition{
    Version: 1,
    Nodes: []stackshift.AutomationNode{
      {ID: "trigger", Type: "trigger.event", Config: json.RawMessage(`{"event_types":["deploy.failed"]}`)},
      {ID: "redeploy", Type: "platform.action", Action: "projects.redeploy", Config: json.RawMessage(`{"project_id":"proj_123"}`)},
    },
    Edges: []stackshift.AutomationEdge{{ID: "e1", Source: "trigger", Target: "redeploy"}},
  },
})
if err != nil {
  return err
}
if _, err := client.Automations.Enable(ctx, automation.ID); err != nil {
  return err
}
run, err := client.Automations.StartRun(ctx, automation.ID, stackshift.StartAutomationRunInput{Test: true})
```

## Definition

Node types: trigger.event, trigger.cron, trigger.webhook, trigger.manual, platform.action, integration.http, control.condition, control.delay and stackie.run. A value of \{ "\$input": "\<node>.\<path>" } reads an earlier node’s output.

```json Tell your billing API about failed deploys theme={null}
{
  "version": 1,
  "nodes": [
    { "id": "trigger", "type": "trigger.event", "config": { "event_types": ["deploy.failed"] } },
    { "id": "notify", "type": "integration.http", "config": {
      "method": "POST",
      "url": "https://api.example.com/hooks/deploys",
      "secret": "BILLING_API_KEY",
      "body": { "event": { "$input": "trigger.id" } }
    } }
  ],
  "edges": [{ "id": "e1", "source": "trigger", "target": "notify" }]
}
```

## Expected result

> [!TIP]
>
> Your scripts drive the same automations and runs shown in the dashboard.

## Related guides

> [card] [Automations overview](https://docs.stackshift.cloud/automations/overview.md)
>
> An automation is a trigger plus steps that run by themselves: on an event, on a schedule, from a webhook URL, or when you press Run.

> [card] [Triggers](https://docs.stackshift.cloud/automations/triggers.md)
>
> Start a run on any event in the catalog, on a cron schedule in your time zone, from a signed webhook URL, or by hand.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.