# Monitors

> List, read, create and change monitors, and switch them on and off.

Reading needs `monitors:read`; the rest, `monitors:write`. Creating and changing monitors needs an operator or admin, and activating or archiving them an admin, as in the app.

## List monitors

```bash
curl "https://pulso.run/api/v1/monitors?status=active" \
  -H "Authorization: Bearer ak_..."
```

Newest first and a [page at a time](https://pulso.run/docs/api/overview.md#lists). Filters, all optional:

| Parameter | Value |
|---|---|
| `status` | `active`, `inactive` or `archived`. Active and inactive when left out. |
| `data_source_id` | A data source's id |
| `category_id` | A category's id |

```json
{
  "monitors": [
    {
      "id": "01M7ZJ3DXSQ8YS1EHDA656QNDK",
      "name": "Duplicate charges",
      "description": "Two captured charges for one order.",
      "status": "active",
      "priority": "high",
      "notification_only": false,
      "data_source": { "id": "01M7ZJ3D…", "name": "Shop database", "type": "postgres" },
      "category": { "id": "01M7ZJ3C…", "name": "Payments" },
      "assignee": null,
      "team": { "id": "01M7ZJ3B…", "name": "Payments Ops" },
      "frequency": "every_5_minutes",
      "frequency_cron": "*/5 * * * *",
      "last_checked_at": "2026-11-22T10:05:00.311Z",
      "created_at": "2026-10-02T08:00:12.000Z",
      "updated_at": "2026-11-20T16:43:09.512Z",
      "url": "https://pulso.run/accounts/…/monitors/01M7ZJ3DXSQ8YS1EHDA656QNDK"
    }
  ],
  "next_cursor": null
}
```

`assignee` and `team` are who the monitor's signals go to.

## Read a monitor

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

Returns `{ "monitor": … }` with the fields above, plus `hour`, `minute` and `week_day` of its schedule, `message_title` and `message_body`, the signal's templates, and `fields`, the columns its data gives signals. Operators and admins also get `query`, `row_identifiers` and `filters`, through a key or connection with `monitors:write` or `data_sources:read_queries`.

## Create a monitor

```bash
curl -X POST https://pulso.run/api/v1/monitors \
  -H "Authorization: Bearer ak_..." -H "Content-Type: application/json" \
  -d '{
    "name": "Duplicate charges",
    "data_source_id": "01M7ZJ3D…",
    "query": "SELECT order_id, count(*) AS charges FROM charges WHERE status = '"'"'captured'"'"' GROUP BY order_id HAVING count(*) > 1",
    "row_identifiers": ["order_id"],
    "frequency": "hourly",
    "minute": 15,
    "priority": "high",
    "assignee": "team:01M7ZJ3B…",
    "message_title": "Order {{signal.order_id}} was charged {{signal.charges}} times"
  }'
```

Answers `201` with `{ "monitor": … }` as [read](https://pulso.run/docs/api/monitors.md#read-a-monitor). It starts inactive: give it a [playbook](https://pulso.run/docs/api/playbooks.md), then [activate](https://pulso.run/docs/api/monitors.md#activate-deactivate-archive) it. `name` and `data_source_id` are required, and `query` too on a SQL data source; try it first with [`run_query`](https://pulso.run/docs/api/data-source-queries.md).

| Field | Value |
|---|---|
| `name`, `description` | Text |
| `data_source_id` | A data source's id |
| `category_id` | A [category's](https://pulso.run/docs/api/account.md) id |
| `query` | For a SQL data source: what each check runs. Each row it returns raises a signal. |
| `row_identifiers` | The columns, or webhook fields, that identify a row, so finding it again raises no new signal. Without them, every check raises a signal for every row. |
| `filters` | Only rows that pass become signals: `[{ "field": "amount", "kind": "number", "operation": "greater_than", "comparator": "100" }]`. `kind` is `string` (`contains`, `equals`, `starts_with`, `ends_with`), `number` (`equals`, `greater_than`, `less_than`) or `boolean` (`is_true`, `is_false`, without `comparator`). |
| `frequency` | `every_5_minutes` (the default), `hourly`, `daily`, `weekly` or `custom` |
| `minute`, `hour`, `week_day` | When an `hourly`, `daily` or `weekly` monitor checks, in UTC. `week_day` 0 is Sunday. |
| `frequency_cron` | For `custom`: a cron expression in UTC, every 5 minutes at most often |
| `priority` | `low`, `medium`, `high` or `critical` |
| `assignee` | Who its signals go to: `member:<id>` or `team:<id>` |
| `notification_only` | `true` runs only its playbook's notification steps |
| `message_title`, `message_body` | New signals' title and message. `{{signal.column}}` takes the row's columns and `{{vars.key}}` the [account's variables](https://pulso.run/docs/concepts/variables-and-address-book.md#variables). |

A field that isn't valid answers `422` and creates nothing, with `errors` by field.

## Change a monitor

```bash
curl -X PATCH https://pulso.run/api/v1/monitors/01M7ZJ3DXSQ8YS1EHDA656QNDK \
  -H "Authorization: Bearer ak_..." -H "Content-Type: application/json" \
  -d '{"priority": "critical", "assignee": null}'
```

Takes the fields of [Create a monitor](https://pulso.run/docs/api/monitors.md#create-a-monitor); only those sent change, and `null` clears `description`, `assignee` or `message_body`. `filters` and `row_identifiers` replace the lists they had. Changing `frequency` needs the `minute`, `hour` or `week_day` it uses, unless the monitor has them already. Returns `{ "monitor": … }`.

When a change to an active SQL monitor changes what it finds (its `query`, `row_identifiers`, `filters` or data source), it first records the rows it already finds, so they don't raise signals, as when [activating](https://pulso.run/docs/api/monitors.md#activate-deactivate-archive) it; send `"skip_prefetch": true` to raise a signal for each of them instead. So it can raise signals, the MCP tool is marked destructive. An archived monitor answers `409`.

## Activate, deactivate, archive

- `POST /api/v1/monitors/:id/activate` starts checking. A SQL monitor first records the rows it already finds, so they don't raise signals; send `{"skip_prefetch": true}` to raise a signal for each of them instead.
- `POST /api/v1/monitors/:id/deactivate` stops checking. Its signals stay.
- `POST /api/v1/monitors/:id/archive` stops it and takes its signals out of the lists.
- `POST /api/v1/monitors/:id/unarchive` brings it back, inactive.

Each returns `{ "monitor": … }` as it is afterwards. Activating an archived monitor answers `409`: unarchive it first.

## Try a playbook script

```bash
curl -X POST https://pulso.run/api/v1/scripts/run \
  -H "Authorization: Bearer ak_..." -H "Content-Type: application/json" \
  -d '{"code": "return { double: input.signal.amount * 2 }", "monitor_id": "01M7ZJ3DXSQ8YS1EHDA656QNDK"}'
```

Runs `code` as a [script step](https://pulso.run/docs/concepts/scripts.md) would and stores nothing. `input` sets what the script gets; without it, the monitor's latest signal, or an empty one with no `monitor_id`. Returns `output`, `logs`, `error` (`null` when it worked), `duration_ms` and the `input` used. A script that fails still answers `200`, with the `error`. Needs `monitors:write` and an operator or admin: it is how an assistant drafts a script before someone adds it to a playbook.
