# Automations endpoints

Every path starts at your [API URL](https://docs.qualithm.com/api.md#find-your-api-url). Every response is JSON, and an error has the [error body](https://docs.qualithm.com/api.md#errors).

## Trigger a webhook automation

`POST /v1/automations/trigger`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate).

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `Idempotency-Key` | header | string | No | A unique key for this request. A retry with the same key and body returns the first response instead of acting again; keys last 24 hours. |

**Request body:** [TriggerAutomationRequest](#triggerautomationrequest)

**Response:** `200` with object in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `404`, `409`, `413`, `415`, `429`, `500`, `503`

```bash
curl -X POST "<your-api-url>/v1/automations/trigger" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '"<body>"'
```

## List every automation template and whether the team's devices can use it

`GET /v1/teams/{teamId}/automation-templates`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `automation.read` permission, which the owner, manager and viewer roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |

**Response:** `200` with array of [TeamAutomationTemplate](#teamautomationtemplate) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `401`, `403`, `404`, `429`, `500`, `503`

```bash
curl "<your-api-url>/v1/teams/<team-id>/automation-templates" \
  -H "Authorization: Bearer <your-api-token>"
```

## List the team's automations

`GET /v1/teams/{teamId}/automations`

Newest first, by `createdAt` then `id`.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `automation.read` permission, which the owner, manager and viewer roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `limit` | query | integer | No | Items per page, 1 to 100. Default 50. |
| `cursor` | query | string | No | A previous page's `nextCursor`, to read the page after it |

**Response:** `200` with [AutomationPage](#automationpage) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `429`, `500`, `503`

```bash
curl "<your-api-url>/v1/teams/<team-id>/automations" \
  -H "Authorization: Bearer <your-api-token>"
```

## Create an automation

`POST /v1/teams/{teamId}/automations`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `automation.write` permission, which the owner and manager roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `Idempotency-Key` | header | string | No | A unique key for this request. A retry with the same key and body returns the first response instead of acting again; keys last 24 hours. |

**Request body:** [CreateAutomationRequest](#createautomationrequest)

**Response:** `201` with [Automation](#automation) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `409`, `413`, `415`, `429`, `500`, `503`

```bash
curl -X POST "<your-api-url>/v1/teams/<team-id>/automations" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"name":"<name>"}'
```

## Test an unsaved automation against a reading without running it

`POST /v1/teams/{teamId}/automations/test`

Evaluates the trigger and chain against the device's latest reading, or a sample. Nothing is run, recorded or counted against quota.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `automation.write` permission, which the owner and manager roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |

**Request body:** [TestDraftAutomationRequest](#testdraftautomationrequest)

**Response:** `200` with [AutomationTest](#automationtest) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `413`, `415`, `429`, `500`, `503`

```bash
curl -X POST "<your-api-url>/v1/teams/<team-id>/automations/test" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"name":"<name>","scopeId":"<scope-id>","payload":{"trigger":{"type":"event","config":{}},"chain":[{"kind":"condition","config":{}}]},"template":"<template>","params":"<params>","deviceId":"<device-id>","sample":{"metrics":{},"topic":"<topic>","state":"online"},"notify":true}'
```

## Get an automation

`GET /v1/teams/{teamId}/automations/{automationId}`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `automation.read` permission, which the owner, manager and viewer roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `automationId` | path | string | Yes | An automation ID: `aut_<zone>_…`; also accepts the legacy `aut_…` |

**Response:** `200` with [Automation](#automation) in `data`.

**Response headers:**

- `ETag`: The resource's version; send it back as If-Match to edit only that version

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `429`, `500`, `503`

```bash
curl "<your-api-url>/v1/teams/<team-id>/automations/<automation-id>" \
  -H "Authorization: Bearer <your-api-token>"
```

## Update an automation

`PATCH /v1/teams/{teamId}/automations/{automationId}`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `automation.write` permission, which the owner and manager roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `automationId` | path | string | Yes | An automation ID: `aut_<zone>_…`; also accepts the legacy `aut_…` |
| `If-Match` | header | string | No | The ETag you last read. The request is refused with 412 when the resource has changed since; omit it to apply the change regardless. |

**Request body:** [UpdateAutomationRequest](#updateautomationrequest)

**Response:** `200` with [Automation](#automation) in `data`.

**Response headers:**

- `ETag`: The resource's version; send it back as If-Match to edit only that version

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `409`, `412`, `413`, `415`, `429`, `500`, `503`

```bash
curl -X PATCH "<your-api-url>/v1/teams/<team-id>/automations/<automation-id>" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"name":"<name>","enabled":true,"scopeId":"<scope-id>","payload":{"trigger":{"type":"event","config":{}},"chain":[{"kind":"condition","config":{}}]},"template":"<template>","params":"<params>"}'
```

## Delete an automation

`DELETE /v1/teams/{teamId}/automations/{automationId}`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `automation.write` permission, which the owner and manager roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `automationId` | path | string | Yes | An automation ID: `aut_<zone>_…`; also accepts the legacy `aut_…` |
| `If-Match` | header | string | No | The ETag you last read. The request is refused with 412 when the resource has changed since; omit it to apply the change regardless. |

**Response:** `204` with no body.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `412`, `429`, `500`, `503`

```bash
curl -X DELETE "<your-api-url>/v1/teams/<team-id>/automations/<automation-id>" \
  -H "Authorization: Bearer <your-api-token>"
```

## List an automation's runs

`GET /v1/teams/{teamId}/automations/{automationId}/runs`

Newest first, by `triggeredAt` then `id`.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `automation.read` permission, which the owner, manager and viewer roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `automationId` | path | string | Yes | An automation ID: `aut_<zone>_…`; also accepts the legacy `aut_…` |
| `limit` | query | integer | No | Items per page, 1 to 100. Default 50. |
| `cursor` | query | string | No | A previous page's `nextCursor`, to read the page after it |

**Response:** `200` with [AutomationRunPage](#automationrunpage) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `429`, `500`, `503`

```bash
curl "<your-api-url>/v1/teams/<team-id>/automations/<automation-id>/runs" \
  -H "Authorization: Bearer <your-api-token>"
```

## Start a run of an automation's chain now

`POST /v1/teams/{teamId}/automations/{automationId}/runs`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `automation.run` permission, which the owner and manager roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `automationId` | path | string | Yes | An automation ID: `aut_<zone>_…`; also accepts the legacy `aut_…` |
| `Idempotency-Key` | header | string | No | A unique key for this request. A retry with the same key and body returns the first response instead of acting again; keys last 24 hours. |

**Response:** `202` with object in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `409`, `429`, `500`, `503`

```bash
curl -X POST "<your-api-url>/v1/teams/<team-id>/automations/<automation-id>/runs" \
  -H "Authorization: Bearer <your-api-token>"
```

## Test an automation against a reading without running it

`POST /v1/teams/{teamId}/automations/{automationId}/test`

Evaluates the saved trigger and chain against the device's latest reading, or a sample. Nothing is run, recorded or counted against quota.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `automation.write` permission, which the owner and manager roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `automationId` | path | string | Yes | An automation ID: `aut_<zone>_…`; also accepts the legacy `aut_…` |

**Request body:** [TestAutomationRequest](#testautomationrequest)

**Response:** `200` with [AutomationTest](#automationtest) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `413`, `415`, `429`, `500`, `503`

```bash
curl -X POST "<your-api-url>/v1/teams/<team-id>/automations/<automation-id>/test" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"deviceId":"<device-id>","sample":{"metrics":{},"topic":"<topic>","state":"online"},"notify":true}'
```

## Issue or rotate an automation's trigger secret

`POST /v1/teams/{teamId}/automations/{automationId}/trigger-secret`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `automation.write` permission, which the owner and manager roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `automationId` | path | string | Yes | An automation ID: `aut_<zone>_…`; also accepts the legacy `aut_…` |
| `Idempotency-Key` | header | string | No | A unique key for this request. A retry with the same key and body returns the first response instead of acting again; keys last 24 hours. |

**Response:** `200` with [AutomationTriggerSecret](#automationtriggersecret) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `409`, `429`, `500`, `503`

```bash
curl -X POST "<your-api-url>/v1/teams/<team-id>/automations/<automation-id>/trigger-secret" \
  -H "Authorization: Bearer <your-api-token>"
```

## List the automation templates a device supports

`GET /v1/teams/{teamId}/devices/{deviceId}/automation-templates`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `automation.read` permission, which the owner, manager and viewer roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `deviceId` | path | string | Yes | A device ID: `dvc_<zone>_…`; also accepts the legacy `dev_…` |

**Response:** `200` with array of [AutomationTemplate](#automationtemplate) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `429`, `500`, `503`

```bash
curl "<your-api-url>/v1/teams/<team-id>/devices/<device-id>/automation-templates" \
  -H "Authorization: Bearer <your-api-token>"
```

## Types

### TriggerAutomationRequest

Optional context for the chain: a JSON object. Any other body, or none, is ignored.

any.

### TeamAutomationTemplate

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `id` | string | Yes |  |
| `version` | integer (int64) | Yes |  |
| `name` | string | Yes |  |
| `description` | string | Yes |  |
| `trigger` | one of `"event"`, `"connectivity"`, `"schedule"`, `"webhook"`, `"manual"` | Yes |  |
| `slots` | array of [AutomationTemplateSlot](#automationtemplateslot) | Yes |  |
| `needs` | array of one of `"sensor"`, `"control"`, `"schedule"`, `"webhook"` | Yes | What the template requires: a reading to watch, a device to command, a schedule or a webhook |
| `usable` | boolean | Yes | Whether at least one of the team's devices can use it |
| `devices` | array of string | Yes | The ids of the team's devices that can use it |

### AutomationTemplateSlot

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `name` | string | Yes |  |
| `kind` | one of `"channel"`, `"device"`, `"metric"`, `"control"`, `"recipient"`, `"range"`, `"schedule"`, `"value"` | Yes |  |

### AutomationPage

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `items` | array of [Automation](#automation) | Yes |  |
| `nextCursor` | string or null | Yes | Pass as `cursor` to read the next page; `null` on the last page |

### Automation

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `id` | string | Yes | An automation ID: `aut_<zone>_…`; also accepts the legacy `aut_…` |
| `teamId` | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |
| `scopeId` | string or null | Yes | Null for a team-wide automation |
| `scopeName` | string or null | Yes |  |
| `name` | string | Yes |  |
| `enabled` | boolean | Yes |  |
| `payload` | [AutomationPayload](#automationpayload) | Yes |  |
| `createdAt` | string (date-time) | Yes | UTC time, RFC 3339 |
| `updatedAt` | string (date-time) | Yes | UTC time, RFC 3339 |
| `templateDrift` | boolean | No | On a single read of a template-built automation: true when its chain no longer matches its template |

### AutomationPayload

An automation's trigger and chain.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `trigger` | [AutomationTrigger](#automationtrigger) | Yes |  |
| `chain` | array of [AutomationConditionStep](#automationconditionstep) or [AutomationActionStep](#automationactionstep) | Yes | Ordered condition and action steps; at least one action |
| `template` | [AutomationTemplateReference](#automationtemplatereference) | No |  |

### AutomationTrigger

What starts the automation's chain.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `type` | one of `"event"`, `"connectivity"`, `"schedule"`, `"webhook"` | Yes |  |
| `config` | object | Yes | The trigger or step's own settings, shaped by its type |

### AutomationConditionStep

A chain step that halts the run when its condition does not hold.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `kind` | `"condition"` | Yes |  |
| `config` | object | Yes | The trigger or step's own settings, shaped by its type |

### AutomationActionStep

A chain step that does something.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `kind` | `"action"` | Yes |  |
| `type` | one of `"device-command"`, `"notification"`, `"outbound-webhook"` | Yes |  |
| `config` | object | Yes | The trigger or step's own settings, shaped by its type |

### AutomationTemplateReference

The template and slot values a template-built automation was expanded from.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `id` | string | Yes |  |
| `version` | integer (int64) | Yes |  |
| `params` | object | Yes |  |

### CreateAutomationRequest

A name, and either a payload or a template

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `name` | string | Yes |  |
| `scopeId` | string or null | No | The scope it applies to; null or absent for team-wide |
| `payload` | object | No | The chain; exclusive with `template` |
| `payload.trigger` | [AutomationTrigger](#automationtrigger) | Yes |  |
| `payload.chain` | array of [AutomationConditionStep](#automationconditionstep) or [AutomationActionStep](#automationactionstep) | Yes | Ordered condition and action steps; at least one action |
| `payload.template` | any | No | A template reference; set by the platform on template-built automations |
| `template` | string | No | A template id to expand the chain from; exclusive with `payload` |
| `params` | any | No | The template's slot values, keyed by slot name; used with `template` |
| `enabled` | boolean | No | Whether its trigger fires; absent creates it turned on |

### TestDraftAutomationRequest

An unsaved automation, as a create sends it with the name optional, and a device or a sample to test against

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `name` | string | No |  |
| `scopeId` | string or null | No | The scope it applies to; null or absent for team-wide |
| `payload` | object | No | The chain; exclusive with `template` |
| `payload.trigger` | [AutomationTrigger](#automationtrigger) | Yes |  |
| `payload.chain` | array of [AutomationConditionStep](#automationconditionstep) or [AutomationActionStep](#automationactionstep) | Yes | Ordered condition and action steps; at least one action |
| `payload.template` | any | No | A template reference; set by the platform on template-built automations |
| `template` | string | No | A template id to expand the chain from; exclusive with `payload` |
| `params` | any | No | The template's slot values, keyed by slot name; used with `template` |
| `deviceId` | string | No | The device whose latest reading the test evaluates; the trigger's own device when absent |
| `sample` | [AutomationTestSample](#automationtestsample) | No |  |
| `notify` | boolean | No | Also send a test notification, marked as a test, to you alone, when a notification would fire |

### AutomationTestSample

A reading to test against in place of the device's latest.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `metrics` | map of number | No | The metrics the sample reports |
| `topic` | string | No | The topic the sample stands for; the trigger's own when absent |
| `state` | one of `"online"`, `"offline"` | No | The connectivity state the sample stands for; the device's when absent |

### AutomationTest

What an automation would do with a reading. Nothing is run, recorded or counted.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `matched` | boolean | Yes | Whether the automation would fire now: its trigger matches and no condition halts |
| `reason` | one of `"no_reading"`, `"device_offline"`, `"out_of_scope"`, `"trigger_not_matched"`, `"condition_halted"`, `"action_failed"`, `"disabled"` | No | Why it would not fire; absent when it would |
| `device` | object or null | Yes | The device tested; null for a sample with no device |
| `reading` | object or null | Yes | The reading evaluated; null when the device has reported none |
| `trigger` | object | Yes |  |
| `trigger.type` | one of `"event"`, `"connectivity"`, `"schedule"`, `"webhook"`, `"manual"` | Yes |  |
| `trigger.matched` | boolean | Yes |  |
| `trigger.state` | object | No | A connectivity trigger's watched state against the device's |
| `trigger.state.expected` | any | Yes |  |
| `trigger.state.actual` | one of `"online"`, `"offline"` or null | Yes |  |
| `compared` | array of [AutomationTestComparison](#automationtestcomparison) | Yes |  |
| `steps` | array of [AutomationRunStep](#automationrunstep) | Yes | The chain as run history records it; an action the test does not take is skipped |
| `actions` | array of [AutomationTestAction](#automationtestaction) | Yes |  |
| `decisions` | array of [Decision](#decision) | Yes | What Qualithm decided on the builder's behalf, most consequential first: at most 6. A value Qualithm doesn't hold is left off. |
| `notification` | object | No | The test notification, when one was asked for |
| `notification.sent` | boolean | Yes |  |
| `notification.channel` | string or null | Yes |  |

### AutomationTestComparison

One comparison the test made against the reading.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `index` | integer (int64) or null | Yes | The chain step compared; null for the trigger |
| `metric` | string | Yes |  |
| `op` | one of `"eq"`, `"ne"`, `"gt"`, `"gte"`, `"lt"`, `"lte"` | Yes |  |
| `expected` | number | Yes | The automation's number |
| `actual` | number or null | Yes | The reading's value; null when the reading lacks the metric |
| `passed` | boolean | Yes |  |

### AutomationRunStep

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `index` | integer (int64) | Yes |  |
| `kind` | one of `"condition"`, `"action"` | Yes |  |
| `type` | one of `"device-command"`, `"notification"`, `"outbound-webhook"` | No |  |
| `outcome` | one of `"passed"`, `"halted"`, `"succeeded"`, `"failed"`, `"skipped"` | Yes |  |
| `error` | string | No |  |
| `durationMs` | number | No |  |

### AutomationTestAction

An action the automation would take; the test takes none. A signing secret is never shown.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `index` | integer (int64) | Yes |  |
| `type` | one of `"device-command"`, `"notification"`, `"outbound-webhook"` | Yes |  |
| `channel` | any | No | A notification's channel |
| `config` | object | Yes | The trigger or step's own settings, shaped by its type |

### Decision

One choice Qualithm made on the builder's behalf.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `key` | string | Yes | Stable identifier for the decision, e.g. `zone` |
| `label` | string | Yes | The decision's name, for people, e.g. `Zone` |
| `value` | string | Yes | The value chosen, as held by its source |
| `source` | string | Yes | Where the value is held, e.g. `scope` or `credential` |
| `docsUrl` | string | Yes | The docs page that explains the default |

### UpdateAutomationRequest

At least one of name, enabled, scopeId, payload or template

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `name` | string | No |  |
| `enabled` | boolean | No | Whether its trigger fires |
| `scopeId` | string or null | No | The scope it applies to; null makes it team-wide |
| `payload` | object | No | A new chain; exclusive with `template` |
| `payload.trigger` | [AutomationTrigger](#automationtrigger) | Yes |  |
| `payload.chain` | array of [AutomationConditionStep](#automationconditionstep) or [AutomationActionStep](#automationactionstep) | Yes | Ordered condition and action steps; at least one action |
| `payload.template` | any | No | A template reference; set by the platform on template-built automations |
| `template` | string | No | A template id to re-expand the chain from; exclusive with `payload` |
| `params` | any | No | The template's slot values, keyed by slot name; used with `template` |

### AutomationRunPage

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `items` | array of [AutomationRun](#automationrun) | Yes |  |
| `nextCursor` | string or null | Yes | Pass as `cursor` to read the next page; `null` on the last page |

### AutomationRun

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `id` | string | Yes | An automation run ID: `run_<zone>_…`; also accepts the legacy `run_…` |
| `automationId` | string | Yes | An automation ID: `aut_<zone>_…`; also accepts the legacy `aut_…` |
| `triggerType` | one of `"event"`, `"connectivity"`, `"schedule"`, `"webhook"`, `"manual"` | Yes |  |
| `status` | one of `"pending"`, `"succeeded"`, `"failed"`, `"skipped"`, `"limited"` | Yes |  |
| `steps` | array of [AutomationRunStep](#automationrunstep) | Yes |  |
| `lastError` | string or null | Yes |  |
| `triggeredAt` | string (date-time) | Yes | UTC time, RFC 3339 |
| `executedAt` | string (date-time) or null | Yes |  |
| `decisions` | array of [Decision](#decision) | No | What Qualithm decided when the run's alert fired: at most six, most consequential first. Absent when the run fired no alert. |

### TestAutomationRequest

A device or a sample to test against; a device is required without a sample

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `deviceId` | string | No | The device whose latest reading the test evaluates; the trigger's own device when absent |
| `sample` | [AutomationTestSample](#automationtestsample) | No |  |
| `notify` | boolean | No | Also send a test notification, marked as a test, to you alone, when a notification would fire |

### AutomationTriggerSecret

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `url` | string | Yes | Where to POST the trigger |
| `secret` | string | Yes | The bearer secret; shown once, never retrievable again |

### AutomationTemplate

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `id` | string | Yes |  |
| `version` | integer (int64) | Yes |  |
| `name` | string | Yes |  |
| `description` | string | Yes |  |
| `trigger` | one of `"event"`, `"connectivity"`, `"schedule"`, `"webhook"`, `"manual"` | Yes |  |
| `slots` | array of [AutomationTemplateSlot](#automationtemplateslot) | Yes |  |
