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

# Triggers

> Start runs of a published procedure on a schedule, when a file arrives in a folder, or when an event happens, and manage triggers through the API.

A trigger starts runs of a published procedure for you. Each trigger has exactly one source: a
schedule, a folder, or an event such as an email arriving. One procedure can have many triggers.
Triggers never start drafts.

You describe a trigger in a short JSON spec and manage it with the `/procedures/triggers`
operations of the API: create it to run as you, copy or change it, and find the runs it started.

Every trigger operation on this page is alpha: it can change without the usual deprecation
notice. See [Stability levels](https://docs.canary.effectiveai.app/getting-started/deprecations.md#stability-levels).

You need an [API key](https://docs.canary.effectiveai.app/getting-started/authentication.md) for a member who is not read-only, and a
published procedure. Creating and changing a trigger needs permission to manage its procedure;
reading one needs permission to run it.

## Spec

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "name": "weekly-reconciliation",
  "procedureId": "premium-reconciliation",
  "version": "live",
  "schedule": {
    "expressions": ["0 9 * * 1"],
    "timezone": "America/New_York"
  },
  "inputs": { "carrier": "Northwind Mutual" }
}
```

| Field | Type | Required | What it does |
| - | - | - | - |
| `name` | string | Yes | The trigger's name, unique in your workspace. The API accepts it in place of the trigger's `id`. Lowercase letters, digits, dots, underscores and hyphens, starting with a letter or digit, at most 128 characters |
| `procedureId` | string | Yes | The procedure to run |
| `version` | `live` or a number | No | `live`, the default, runs the live version at each firing. A number pins that exact version |
| `projectId` | string or null | No | The Project the trigger's runs belong to, or null for none. The procedure must be installed in it |
| `inputs` | object | No | Fixed inputs for every run |
| `schedule` | object | One of three | Fire on a schedule |
| `folder` | object | One of three | Fire for each new file in a folder |
| `event` | object | One of three | Fire for each matching event |

The spec is strict: give exactly one of `schedule`, `folder` and `event`, and no other fields.
A name can't change later, and a deleted trigger's name stays taken. Who the trigger runs as and
whether it is enabled are not part of the spec: each create and replace says them in its own
`enabled` and `runAs`, which are never stored with the spec. A spec copied from a trigger
therefore never carries anyone's authority with it.

Prefer `"version": "live"`. It follows the procedure's
[live version](https://docs.canary.effectiveai.app/procedures/concepts/runs-and-versions.md#the-live-version). A newly published version
becomes live on its own only when it keeps the live version's inputs and output, so the trigger's
`inputs` keep working, and `live` can lag behind the newest version. Someone can still make a
version with different inputs live. The trigger's fixed `inputs` may then no longer match, and its
firings fail to start runs; `lastError` says why. When you make such a version live,
[replace the trigger's spec](#replace-the-spec) with `inputs` that match it.

### Schedule

| Field | What it does |
| - | - |
| `schedule.expressions` | Up to ten cron expressions, such as `0 9 * * 1` for 09:00 every Monday |
| `schedule.timezone` | One IANA time zone for all the expressions, such as `America/New_York` |

Each expression must fire no more often than once an hour.

### Folder

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "folder": {
    "uri": "team://claims/incoming",
    "input": "claim_file"
  }
}
```

| Field | What it does |
| - | - |
| `folder.uri` | The folder to watch. The URI shown is illustrative |
| `folder.input` | The procedure input that receives each new file |

Each new file in the folder starts one run, with the file bound to `folder.input` as
`{ "uri": "artifact://<id>" }`. That input name can't also appear in `inputs`.

### Event

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "event": {
    "type": "email_received",
    "match": { "senderEmails": ["claims@northwind.example"] },
    "input": "email"
  }
}
```

| Field | What it does |
| - | - |
| `event.type` | `email_received`, `rsl_log_written` or `procedure_run_terminal` |
| `event.match` | Filters on the event. Each field you give must hold. Leave it out to take every event of the type |
| `event.input` | The procedure input that receives the event. It can't also appear in `inputs` |

Events are always your workspace's own. The input receives the whole event, with its details
under `payload`.

**`email_received`** fires when email arrives at one of your workspace's inbound addresses that
points to the trigger. See [Receive email at an address](https://docs.canary.effectiveai.app/guides/email-addresses.md#set-up-a-procedure-trigger)
to create the address. The payload includes the sender, subject, plain-text body and references
to attachments.

| `match` field | Holds when |
| - | - |
| `senderEmails` | The email is from one of these senders, compared without regard to case |

**`rsl_log_written`** fires once for each write an [RSL submission log](https://docs.canary.effectiveai.app/rsl/programs-on-effective.md#submission-logs)
keeps: opening the log, and every write that records entries. A preview, a refused write, and a
retry answered from its idempotency key fire nothing.

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "event": {
    "type": "rsl_log_written",
    "match": {
      "programs": ["northwind-small-commercial"],
      "steps": ["signed_off"],
      "roles": ["manager"]
    },
    "input": "write"
  }
}
```

| `match` field | Holds when |
| - | - |
| `programs` | The log is on one of these programs |
| `steps` | The write recorded an entry with one of these step names |
| `roles` | The write was made in one of these program roles |
| `statuses` | The write left the log at one of these statuses, such as `ready` or `refused` |

The step names are `opened`, `answered`, `noted`, `signed_off`, `attached`, `retracted`,
`withdrawn`, `renamed`, `receipt`, `offered`, `accepted`, `closed` and `moved`. The statuses are
`incomplete`, `referred`, `ineligible`, `ready`, `accepted`, `refused` and `ended`.

The payload holds `program`, `releaseVersion`, `log`, `head`, `steps`, `role`, `actor` and
`status`, and `procedureId` and `procedureRunId` when a procedure made the write. It holds no
answers or outcomes: read the log for those. `stage` and `decision` are also present but
deprecated; read `status`.

A procedure that writes to the log it watches starts itself again unless `match` leaves its own
writes out. Match the steps or roles of the other writers, and write in a different role.

**`procedure_run_terminal`** fires when a procedure run in your workspace finishes: completed,
failed or cancelled.

| `match` field | Holds when |
| - | - |
| `procedureId` | The run is of this procedure |
| `outcomes` | The run ended in one of these: `completed`, `failed`, `cancelled` |

The payload holds `logical_run_id`, `procedure_id`, `procedure_version` and `outcome`. Set
`match.procedureId` to the procedure you follow: without it, the trigger's own runs finishing
start it again.

### Declare the event input

Declare the event input with a schema that requires what the procedure reads, and allows the rest:

````markdown loss-notice-intake.procedure.md theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
---
kind: procedure@v0
id: loss-notice-intake

inputs:
  email: { schema: email-event }
outputs:
  intake: { schema: intake }
---

# Loss notice intake

Record who reported a loss by email.

## Record the sender

```yaml complete id=recorded
output: intake
value:
  reportedBy: $inputs.email.payload.senderEmail
  subject: $inputs.email.payload.subject
```

## Resources

```yaml schema id=email-event
type: object
additionalProperties: true
required: [type, payload]
properties:
  type: { const: email_received }
  payload:
    type: object
    additionalProperties: true
    required: [senderEmail, subject, body]
    properties:
      senderEmail: { type: string }
      subject: { type: string }
      body: { type: string }
```

```yaml schema id=intake
type: object
additionalProperties: false
required: [reportedBy, subject]
properties:
  reportedBy: { type: string }
  subject: { type: string }
```
````

## Create a trigger

### Create it enabled

Publish the procedure first. Then send the spec with `"enabled": true` and `"runAs": "self"`:

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
curl --request POST \
  --url "https://api.canary.effectiveai.app/api/v2/procedures/triggers" \
  --header "Authorization: Bearer $EFFECTIVE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "weekly-reconciliation",
    "procedureId": "premium-reconciliation",
    "version": "live",
    "schedule": { "expressions": ["0 9 * * 1"], "timezone": "America/New_York" },
    "inputs": { "carrier": "Northwind Mutual" },
    "enabled": true,
    "runAs": "self"
  }'
```

The responses on this page are illustrative and abbreviated; your ids and times differ. The status
is `201`:

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "id": "4c2e9a71-8b3d-4f60-a5e2-1d7b9c0f3e48",
  "name": "weekly-reconciliation",
  "procedureId": "premium-reconciliation",
  "version": "live",
  "projectId": null,
  "kind": "schedule",
  "schedule": { "expressions": ["0 9 * * 1"], "timezone": "America/New_York" },
  "folder": null,
  "event": null,
  "inputs": { "carrier": "Northwind Mutual" },
  "revision": 1,
  "enabled": true,
  "runAs": { "userId": "1042", "state": "valid" },
  "nextRunAt": "2026-11-30T14:00:00.000Z",
  "runCount": 0,
  "lastError": null,
  "runTriggerId": "procedure-trigger@v1:weekly-reconciliation"
}
```

The trigger is created and enabled together, and a schedule fires from its next time. Effective
checks the version and `inputs` as it would for a run, and that the folder or Project exists.
A spec it can't accept is refused with `422 invalid_trigger`, such as a version that isn't
published, inputs that don't match it, or a cron expression that fires more than hourly. If the
trigger can't be enabled, the request is refused and nothing is created. A refused request, any
`4xx`, stores nothing, so you can fix it and send it again. After a `5xx` or a lost response, the
trigger may exist and be enabled, because Effective registers its schedule after storing it. Get
the trigger by name: if it exists, [enable it](#enable-a-disabled-trigger) again rather than
creating it again. Setting `projectId` also needs permission to manage that Project.

* **`enabled` is required.** There is no default. `"enabled": true` needs `"runAs": "self"`, and
  `"enabled": false` takes no `runAs`; either mismatch is refused with `400 invalid_request`.
* **Who it runs as.** `"runAs": "self"`, the only value, records you as the person the trigger's
  runs act as. You can only authorize yourself.
* **Which credentials can enable.** Enable signed in, or with an API key that acts as you in full.
  Resource-scoped API keys and app credentials are refused with `403 forbidden` before anything is
  created, because a later run would carry your access rather than the key's limits.
* **Every firing checks again.** Each run starts with your access at that time. If you can no
  longer run the procedure, later firings don't start runs.

`runAs.state` is `stale` when the recorded authorization belongs to an earlier revision or can no
longer be used. [Enable the trigger](#enable-a-disabled-trigger) again to fix it.

### Create it disabled

To set a trigger up without turning it on, send `"enabled": false` and leave out `runAs`. The
trigger is created disabled and runs as no one. Any credential that can manage the procedure can
do this, including a resource-scoped API key.

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "name": "weekly-reconciliation",
  "procedureId": "premium-reconciliation",
  "schedule": { "expressions": ["0 9 * * 1"], "timezone": "America/New_York" },
  "inputs": { "carrier": "Northwind Mutual" },
  "enabled": false
}
```

The response has `"enabled": false` and `"runAs": null`. Enable it later as below.

### Enable a disabled trigger

Turn a disabled trigger on, to run as you:

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
curl --request POST \
  --url "https://api.canary.effectiveai.app/api/v2/procedures/triggers/weekly-reconciliation/enable" \
  --header "Authorization: Bearer $EFFECTIVE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{ "runAs": "self" }'
```

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "id": "4c2e9a71-8b3d-4f60-a5e2-1d7b9c0f3e48",
  "name": "weekly-reconciliation",
  "revision": 1,
  "enabled": true,
  "runAs": { "userId": "1042", "state": "valid" },
  "nextRunAt": "2026-11-30T14:00:00.000Z",
  "runTriggerId": "procedure-trigger@v1:weekly-reconciliation"
}
```

Enabling checks the version, `inputs` and Project again first, and needs the same credentials as
creating a trigger enabled. Enabling an enabled trigger records you again and changes nothing
else.

## Manage triggers

Every path below takes the trigger's `id` or its `name`. A trigger set up outside the API that
watches an event type or `match` field the API doesn't offer is left out of lists and answers
`404`.

### List

List triggers, ordered by name. Filter with `procedureId` and `projectId`, and set `limit`
(at most 200). For the next page, send the response's `nextCursor` as `cursor` with the same
filters and `limit`; it is null on the last page. See [Pagination](https://docs.canary.effectiveai.app/getting-started/pagination.md).

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
curl --request GET \
  --url "https://api.canary.effectiveai.app/api/v2/procedures/triggers?procedureId=premium-reconciliation&limit=50" \
  --header "Authorization: Bearer $EFFECTIVE_API_KEY"
```

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "items": [{ "name": "weekly-reconciliation", "kind": "schedule", "enabled": true }],
  "nextCursor": null
}
```

### Get

Get one trigger, with its spec, `revision`, whether it is enabled, who it runs as, `nextRunAt`,
`runCount` and `lastError`, the reason its latest firing didn't start a run, if one didn't:

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
curl --request GET \
  --url "https://api.canary.effectiveai.app/api/v2/procedures/triggers/weekly-reconciliation" \
  --header "Authorization: Bearer $EFFECTIVE_API_KEY"
```

### Copy a trigger

A trigger you get is not a request you can send back as it is. Its spec is these fields of the
response: `name`, `procedureId`, `version`, `projectId`, `schedule`, `folder`, `event` and
`inputs`. The rest, `id`, `kind`, `revision`, `enabled`, `runAs`, `nextRunAt`, `runCount`,
`lastError` and `runTriggerId`, are its state. A create or replace that sends a state field is
refused with `400 invalid_request`, so whose access a trigger runs with is never copied.

To copy a trigger, send its spec fields to create under a new `name`, with your own `enabled`
and `runAs`. Unused sources can stay `null`:

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
curl --request POST \
  --url "https://api.canary.effectiveai.app/api/v2/procedures/triggers" \
  --header "Authorization: Bearer $EFFECTIVE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "weekly-reconciliation-contoso",
    "procedureId": "premium-reconciliation",
    "version": "live",
    "projectId": null,
    "schedule": { "expressions": ["0 9 * * 1"], "timezone": "America/New_York" },
    "folder": null,
    "event": null,
    "inputs": { "carrier": "Contoso Casualty" },
    "enabled": true,
    "runAs": "self"
  }'
```

### Replace the spec

Send the trigger's spec fields, changed, with `expectedRevision` set to the `revision` you last
read and `enabled` saying whether the new spec runs. `name` can't change: a replace that sends
another name is refused with `422 invalid_trigger`.

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
curl --request PUT \
  --url "https://api.canary.effectiveai.app/api/v2/procedures/triggers/weekly-reconciliation" \
  --header "Authorization: Bearer $EFFECTIVE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "weekly-reconciliation",
    "procedureId": "premium-reconciliation",
    "version": "live",
    "projectId": null,
    "schedule": { "expressions": ["0 9 * * 1", "0 9 * * 4"], "timezone": "America/New_York" },
    "folder": null,
    "event": null,
    "inputs": { "carrier": "Northwind Mutual" },
    "expectedRevision": 1,
    "enabled": true,
    "runAs": "self"
  }'
```

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "name": "weekly-reconciliation",
  "schedule": { "expressions": ["0 9 * * 1", "0 9 * * 4"], "timezone": "America/New_York" },
  "revision": 2,
  "enabled": true,
  "runAs": { "userId": "1042", "state": "valid" }
}
```

The authorization a trigger had was given for its old spec, so a replace never keeps it. With
`"enabled": true` and `"runAs": "self"`, the new spec is enabled in the same request, to run as
you, with the same credentials as [creating it enabled](#create-it-enabled). With
`"enabled": false`, the trigger ends up disabled and runs as no one.

A replace isn't atomic. The trigger is disabled while its spec is replaced, and if the request
fails after that, it is left disabled at its new `revision`, even with `"enabled": true`. After
an error, get the trigger. If it is at the new `revision` and disabled,
[enable it](#enable-a-disabled-trigger) or replace it again from that `revision`. If someone
changed the trigger since `expectedRevision`, the replace is refused with `409 conflict` and the
trigger is unchanged; get it again and decide.

### Disable

Disable the trigger. It stops firing, and runs it already started go on. Enabling it again
records whoever enables it.

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
curl --request POST \
  --url "https://api.canary.effectiveai.app/api/v2/procedures/triggers/weekly-reconciliation/disable" \
  --header "Authorization: Bearer $EFFECTIVE_API_KEY"
```

### Run now

Run now starts one run of a schedule trigger immediately, as you, with its version and inputs,
whether or not it is enabled. It doesn't move the schedule. Folder and event triggers fire only
from their files and events, and are refused with `422 invalid_trigger`. Run now needs permission
to run the procedure. As with enable, resource-scoped API keys and app credentials are refused
with `403`.

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
curl --request POST \
  --url "https://api.canary.effectiveai.app/api/v2/procedures/triggers/weekly-reconciliation/run-now" \
  --header "Authorization: Bearer $EFFECTIVE_API_KEY"
```

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{ "outcome": "requested" }
```

The status is `202`. `requested` means a run is starting; find it as in
[Find a trigger's runs](#find-a-triggers-runs). `already_running` means an earlier run-now of this
trigger is still starting, so no run was added.

### Delete

Delete the trigger. It stops firing, and runs it already started go on and keep naming it. Its
name stays taken. The response is `204` with no body.

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
curl --request DELETE \
  --url "https://api.canary.effectiveai.app/api/v2/procedures/triggers/weekly-reconciliation" \
  --header "Authorization: Bearer $EFFECTIVE_API_KEY"
```

### Retries

Trigger operations take no `Idempotency-Key`. Each is safe to repeat for its own reason:

| Operation | A repeat after it succeeded |
| - | - |
| Create | `409 conflict`, because the name is taken. Get the trigger by name to see what was stored |
| Replace | `409 conflict`, because the revision moved. Get the trigger to see its `revision`, and enable it if a failed replace left it disabled |
| Enable | Records you again and changes nothing else |
| Disable | Changes nothing |
| Run now | `already_running` while the earlier run is still starting |
| Delete | `404 not_found` |
| List, get | Read-only |

A create refused with a `4xx` stored nothing, so you can send it again under the same name. After
a `5xx` or a lost response, get the trigger by name: if it exists, it may already be enabled, so
[enable it](#enable-a-disabled-trigger) again rather than creating it again.

### Errors

Errors use the [shared envelope](https://docs.canary.effectiveai.app/getting-started/errors.md).

| Status | `code` | When |
| - | - | - |
| 400 | `invalid_request` | The body, query or path is malformed, such as an unknown or state field, no source or two sources, an `event.input` also in `inputs`, no `enabled`, `"enabled": true` without `"runAs": "self"`, or `runAs` with `"enabled": false` |
| 400 | `invalid_cursor` | The `cursor` expired, or was sent with different filters or `limit` |
| 403 | `forbidden` | You may not manage the trigger, its procedure or its Project, you're a read-only member, or your credential can't enable a trigger or run it now |
| 404 | `not_found` | No such trigger, or you may not run its procedure |
| 409 | `conflict` | The name is taken, `expectedRevision` is stale, or the trigger changed during the request. Read it again |
| 413 | | The request body is larger than 256 KiB on create or replace, or 4 KiB on enable |
| 422 | `invalid_trigger` | Effective can't save or change the trigger as asked, such as an unpublished version, mismatched inputs, a replace that changes `name`, or run-now on a folder or event trigger |
| 503 | `temporarily_unavailable` | Triggers are temporarily unavailable. Retry |

## How firings behave

* **At most one run per firing.** A trigger starts at most one run for each scheduled time, file
  or event.
* **No overlap for schedules.** A scheduled firing is skipped while an earlier run from the same
  trigger is still active. Folder and event triggers start a run for each file or event, even
  while earlier runs are still active.
* **No catch-up.** Enabling a trigger doesn't replay firings missed while it was disabled.
* **The version is chosen per firing.** With `"version": "live"`, each firing starts the version
  that is live at that moment, and the run keeps it.

## Find a trigger's runs

A run a trigger started has `cause.kind` `trigger` and the trigger's `runTriggerId` in
`cause.triggerId`. To list a trigger's runs, pass `runTriggerId` as `triggerId`:

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
curl --request GET --get \
  --url "https://api.canary.effectiveai.app/api/v2/procedures/runs" \
  --header "Authorization: Bearer $EFFECTIVE_API_KEY" \
  --data-urlencode "triggerId=procedure-trigger@v1:weekly-reconciliation"
```

Use the `runTriggerId` your trigger returns. `--data-urlencode` encodes the `@` and `:` it
contains.

## See also

* [Run procedures from your system](https://docs.canary.effectiveai.app/guides/procedures.md): start runs from your own
  events through the API.
* [Receive email at an address](https://docs.canary.effectiveai.app/guides/email-addresses.md): point an inbound address at an
  `email_received` trigger.
* [Runs and versions](https://docs.canary.effectiveai.app/procedures/concepts/runs-and-versions.md): the live version and what a run
  pins.
* [`wait`](https://docs.canary.effectiveai.app/procedures/reference/nodes/wait): pause inside a run until a time or a condition.


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