# Playbooks

> Read and replace a monitor's playbook and playbook templates, and build a monitor with an assistant.

A [playbook](https://pulso.run/docs/concepts/playbooks.md) is a list of steps. The API reads and writes it as JSON, the same steps the playbook editor saves, and checks them the same way. Reading needs `monitors:read`; writing, `monitors:write` and an operator or admin.

## Steps

Each step is `{ "id", "type", "data" }`:

```json
{
  "id": "6f1c2a90-3d4b-4e8a-9a51-0c7d2e5b8f13",
  "type": "task",
  "data": { "title": "Refund order {{signal.order_id}}", "description": "<p>Refund the second charge in Stripe.</p>", "assignee": "__current__", "team": "__current__" }
}
```

`id` names the step: keep it when changing a playbook, and leave it out on a new step to get one. Text fields take the same [variables](https://pulso.run/docs/concepts/playbooks.md#using-data-in-steps) as the editor, as `{{signal.column}}`, `{{vars.key}}` and `{{system_name.key}}`.

`GET /api/v1/playbook_step_types` lists every type with what its `data` holds:

```json
{
  "step_types": [
    { "type": "commentAction", "description": "Comments on the signal.", "data": { "message": "Text" } },
    …
  ]
}
```

Branches (`questionBranchAction` and `automaticBranchAction`) hold their own steps in `data.branches[].items`.

## A monitor's playbook

```bash
curl https://pulso.run/api/v1/monitors/01M7ZJ3DXSQ8YS1EHDA656QNDK/playbook \
  -H "Authorization: Bearer ak_..."
```

Returns `{ "items": [ … ] }`, the steps each new signal gets.

```bash
curl -X PUT https://pulso.run/api/v1/monitors/01M7ZJ3DXSQ8YS1EHDA656QNDK/playbook \
  -H "Authorization: Bearer ak_..." -H "Content-Type: application/json" \
  -d '{"items": [
        {"type": "setPriorityAction", "data": {"priority": "high"}},
        {"type": "task", "data": {"title": "Refund order {{signal.order_id}}", "assignee": "__current__", "team": "__current__"}}
      ]}'
```

Replaces every step and returns `{ "items": [ … ] }` as saved. Signals already raised keep the steps they got. If a step isn't valid, or a field has the wrong type (a number where text goes, say), nothing is saved and it answers `422` with `errors` by the step's place, as `items[1].branches[0].items[0].title`. The change is in the monitor's audit log, as one made in the editor.

The signal's title and message are the monitor's `message_title` and `message_body`: [change them on the monitor](https://pulso.run/docs/api/monitors.md#change-a-monitor).

## Playbook templates

A template is a list of steps that several playbooks run through a `templateRef` step, so changing it changes all of them.

### List templates

```bash
curl https://pulso.run/api/v1/playbook_templates \
  -H "Authorization: Bearer ak_..."
```

Most recently changed first:

```json
{
  "playbook_templates": [
    { "id": "01M7ZJ3E…", "name": "Refund a charge", "description": "Ask payments to refund it." }
  ]
}
```

### Read a template

```bash
curl https://pulso.run/api/v1/playbook_templates/01M7ZJ3E… \
  -H "Authorization: Bearer ak_..."
```

```json
{
  "playbook_template": {
    "id": "01M7ZJ3E…",
    "name": "Refund a charge",
    "description": "Ask payments to refund it.",
    "items": [ … ],
    "monitors": [ { "id": "01M7ZJ3DXSQ8YS1EHDA656QNDK", "name": "Duplicate charges" } ],
    "updated_at": "2026-11-20T16:43:09.512Z"
  }
}
```

`monitors` are those that use it.

### Create a template

```bash
curl -X POST https://pulso.run/api/v1/playbook_templates \
  -H "Authorization: Bearer ak_..." -H "Content-Type: application/json" \
  -d '{"name": "Refund a charge", "items": [
        {"type": "task", "data": {"title": "Refund order {{signal.order_id}}", "assignee": "__current__", "team": "__current__"}}
      ]}'
```

`name` is required; `description` and `items` are optional. Answers `201` with the template as [read](https://pulso.run/docs/api/playbooks.md#read-a-template).

### Change a template

```bash
curl -X PATCH https://pulso.run/api/v1/playbook_templates/01M7ZJ3E… \
  -H "Authorization: Bearer ak_..." -H "Content-Type: application/json" \
  -d '{"description": "Ask payments to refund the second charge."}'
```

Changes `name` or `description`; `items` replaces its steps, for every monitor that uses it. Returns the template as [read](https://pulso.run/docs/api/playbooks.md#read-a-template).

Steps are checked as in a monitor's playbook, with the same `422`.

## With an assistant

Connected through [MCP](https://pulso.run/docs/api/mcp.md), an assistant can build a monitor from a sentence, as you and with your role. It reads the schema, tries the SQL, and creates the monitor and its playbook. The monitor starts inactive, so nothing runs until you, or the assistant once you agree, activate it.

> **You:** Watch for orders charged twice in the shop database. The payments team should refund them.
>
> **Assistant:** *calls `list_data_sources`, `get_data_source_schema` and `run_query`*
> This finds 3 orders right now:
> `SELECT order_id, count(*) AS charges FROM charges WHERE status = 'captured' GROUP BY order_id HAVING count(*) > 1`
>
> *calls `list_teams`, `create_monitor`, `list_playbook_step_types` and `replace_monitor_playbook`*
> I created **Duplicate charges**, checking every hour and assigned to Payments Ops, with a playbook that sets the priority to high and asks for the refund. It's inactive. Activate it? The 3 orders it finds now won't raise signals.
>
> **You:** Yes.
>
> **Assistant:** *calls `activate_monitor`*
> It's active.

`update_monitor`, `replace_monitor_playbook` and `update_playbook_template` change what is running, so they are marked destructive and your client can ask you first.
