# Add a trigger to an automation.

`POST /o/{org}/p/{project}/automations/{automation}/triggers`

A `webhook` trigger's secret is returned once, in this response. A change by someone other than `created_by` makes them its runner, as an edit does.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `org` | path | string | yes | The org's slug or id. A caller with no role in the org gets `404`. |
| `project` | path | string | yes | A Project's handle (name) or id, resolved inside `{org}` — OR the reserved sentinel `_` meaning "no Project" (a direct-repo / repo-less dispatch on `POST`; "no Project constraint, resolve by session id alone" everywhere else). A real handle that doesn't match the session's actual Project is `404`. |
| `automation` | path | string | yes | The automation's id. |

## Request body

- `kind` (string, required, one of `github`, `schedule`, `webhook`, `linear`, `email`, `session`)
- `events` (array of string | string, optional): Required and non-empty for kinds `github` and `linear`; empty or absent otherwise.
- `branch_patterns` (array of string, optional)
- `config` (TriggerConfig, optional)
  - `labels` (array of string, optional): Kind `github`: any-of label filter. Kind `linear`: the labels whose addition fires `linear.issue.labeled` (required with it).
  - `teams` (array of string, optional): Kind `linear`: Linear team keys; empty means every public team.
  - `states` (object, optional): Kind `linear`: Linear state name -> mode (required with `linear.issue.state_changed`). `plan` starts a read-only run that posts its plan as a comment on the issue through the runner's Linear connection; `exec` starts an ordinary run.
  - `authors` (array of string, optional): Kind `github`: GitHub logins.
  - `cron` (string, optional): Kind `schedule`: a 5-field cron expression, at most hourly (every 10 minutes for a wake). Exactly one of `cron` and `every` is sent; `every` is stored as its cron.
  - `every` (string, optional, one of `10m`, `30m`, `1h`, `1d`): Kind `schedule`: the plain-language schedule, read in `timezone` (`1d` is midnight); stored and returned as `cron`. `10m` and `30m` need a wake (the automation's `session_id`).
  - `timezone` (string, optional): Kind `schedule`: an IANA timezone; UTC when omitted.
  - `from` (array of string, optional): Kind `email`: senders that may start a run, each an address (`dana@acme.com`) or a domain (`acme.com`, `@acme.com`); empty means anyone. Mail from anyone else, or whose domain did not pass DMARC at Gmail, is skipped.
  - `label` (string, optional): Kind `email`: a Gmail label name; only new mail carrying it fires (a Gmail filter that adds the label picks the mail). Without it, any new inbox message fires.
  - `history_id` (string, optional): Kind `email`: the Gmail history the trigger has read up to. An email trigger reads its runner's connected Gmail (primary account) about once a minute; each new message (sender, subject, date, the plain-text body up to 64 KB, at most 20 attachments as the run's files) starts one run, deduped on its Gmail id. Mail sent by the runner never fires. Adding one needs a Gmail connection (422 `GMAIL_NOT_CONNECTED`) and makes the caller its runner.
  - `history_account` (string, optional): Kind `email`: the Gmail account `history_id` belongs to. When the runner's account changes, the trigger reads from now.
  - `agents` (array of string, optional): Kind `session` (required): the runs it follows, by saved agent id, or a harness name for runs with no saved agent. When such a run in the Project ends, the automation starts with the ended run's status, outcome, pull request, structured result and final message as its event. Its runner must be able to read that run.
  - `ended` (array of string, optional): Kind `session`: the ways the run ended that fire it; `[completed]` when omitted.
  - `outcome` (array of string, optional): Kind `session`: fire only when the run's structured result (its `output_schema` answer, when valid) has one of these as `outcome`, such as `approved` or `changes_requested`. Absent means any.
  - `max_depth` (integer, optional): Kind `session`: how many session triggers in a row may follow one run something else started; 3 when omitted. Runs on one pull request count together, so a review and fix loop through GitHub events ends too.

## Example request

```bash
curl -X POST "https://api.phoenix.so/o/$RUSH_ORG/p/_/automations/$AUTOMATION/triggers" \
  -H "Authorization: Bearer $RUSH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "github"
  }'
```

```typescript
const org = process.env.RUSH_ORG;
const automation = process.env.AUTOMATION;

const res = await fetch(`https://api.phoenix.so/o/${org}/p/_/automations/${automation}/triggers`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.RUSH_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    kind: "github",
  }),
});

console.log(res.status, await res.json());
```

```python
import os

import requests

org = os.environ["RUSH_ORG"]
automation = os.environ["AUTOMATION"]

res = requests.post(
    f"https://api.phoenix.so/o/{org}/p/_/automations/{automation}/triggers",
    headers={"Authorization": f"Bearer {os.environ['RUSH_TOKEN']}"},
    json={
        "kind": "github",
    },
)

print(res.status_code, res.json())
```

## Responses

### 201

Created.

- `trigger` (AutomationTrigger, required): An API key reads it with every null and empty field left out (`events`, `branch_patterns`, an empty `config`, an unset `next_fire_at` or `last_fired_at`).
  - `id` (string, required)
  - `kind` (string, required, one of `github`, `schedule`, `webhook`, `linear`, `email`, `session`)
  - `events` (array of string | string, optional): GitHub event keys (kind `github`) or Linear event keys (kind `linear`).
  - `branch_patterns` (array of string, optional): Globs on a pull request's base branch (kind `github` only).
  - `config` (TriggerConfig, optional)
    - `labels` (array of string, optional): Kind `github`: any-of label filter. Kind `linear`: the labels whose addition fires `linear.issue.labeled` (required with it).
    - `teams` (array of string, optional): Kind `linear`: Linear team keys; empty means every public team.
    - `states` (object, optional): Kind `linear`: Linear state name -> mode (required with `linear.issue.state_changed`). `plan` starts a read-only run that posts its plan as a comment on the issue through the runner's Linear connection; `exec` starts an ordinary run.
    - `authors` (array of string, optional): Kind `github`: GitHub logins.
    - `cron` (string, optional): Kind `schedule`: a 5-field cron expression, at most hourly (every 10 minutes for a wake). Exactly one of `cron` and `every` is sent; `every` is stored as its cron.
    - `every` (string, optional, one of `10m`, `30m`, `1h`, `1d`): Kind `schedule`: the plain-language schedule, read in `timezone` (`1d` is midnight); stored and returned as `cron`. `10m` and `30m` need a wake (the automation's `session_id`).
    - `timezone` (string, optional): Kind `schedule`: an IANA timezone; UTC when omitted.
    - `from` (array of string, optional): Kind `email`: senders that may start a run, each an address (`dana@acme.com`) or a domain (`acme.com`, `@acme.com`); empty means anyone. Mail from anyone else, or whose domain did not pass DMARC at Gmail, is skipped.
    - `label` (string, optional): Kind `email`: a Gmail label name; only new mail carrying it fires (a Gmail filter that adds the label picks the mail). Without it, any new inbox message fires.
    - `history_id` (string, optional): Kind `email`: the Gmail history the trigger has read up to. An email trigger reads its runner's connected Gmail (primary account) about once a minute; each new message (sender, subject, date, the plain-text body up to 64 KB, at most 20 attachments as the run's files) starts one run, deduped on its Gmail id. Mail sent by the runner never fires. Adding one needs a Gmail connection (422 `GMAIL_NOT_CONNECTED`) and makes the caller its runner.
    - `history_account` (string, optional): Kind `email`: the Gmail account `history_id` belongs to. When the runner's account changes, the trigger reads from now.
    - `agents` (array of string, optional): Kind `session` (required): the runs it follows, by saved agent id, or a harness name for runs with no saved agent. When such a run in the Project ends, the automation starts with the ended run's status, outcome, pull request, structured result and final message as its event. Its runner must be able to read that run.
    - `ended` (array of string, optional): Kind `session`: the ways the run ended that fire it; `[completed]` when omitted.
    - `outcome` (array of string, optional): Kind `session`: fire only when the run's structured result (its `output_schema` answer, when valid) has one of these as `outcome`, such as `approved` or `changes_requested`. Absent means any.
    - `max_depth` (integer, optional): Kind `session`: how many session triggers in a row may follow one run something else started; 3 when omitted. Runs on one pull request count together, so a review and fix loop through GitHub events ends too.
  - `next_fire_at` (string | null, optional): The next schedule slot, or when an email trigger next reads Gmail; null for other kinds.
  - `last_fired_at` (string | null, optional)
  - `created_at` (string, required)
  - `webhook_url` (string, optional): Kind `webhook` only: POST here with `Authorization: Bearer <secret>`; the body (at most 64 KB) becomes the event text and an `Idempotency-Key` header dedups retries. Answers 202 with a TriggerFireOutcome, and 401 for an unknown trigger or a wrong secret alike.
  - `webhook_secret` (string, optional): Kind `webhook`, only in the response that created or rotated it.

### 400

Malformed request.

### 401

No bearer, an unknown, revoked or expired one, or an API key on a route keys cannot call.

### 403

The caller is neither the automation's creator nor an org admin (`FORBIDDEN`).

### 404

No such resource for the caller, including one in an org the caller is not in or a Project that is private to someone else.

### 422

Invalid schedule (`INVALID_SCHEDULE`), or a `linear` trigger whose runner has no Linear connection (`LINEAR_NOT_CONNECTED`), or an `email` trigger whose runner has no Gmail connection (`GMAIL_NOT_CONNECTED`).

### 429

The account is over its request budget, 1,800 a minute shared by the person's API keys and console on every API host (`RATE_LIMITED`). The error names the limit. Wait `Retry-After` seconds.

## Example response (201)

```json
{
  "trigger": {
    "id": "3f6c1e2a-8b4d-4c1e-9a7f-2d5b6e8c0a14",
    "kind": "github",
    "events": ["issue_comment.mention"],
    "branch_patterns": ["string"],
    "config": {
      "labels": ["string"],
      "teams": ["string"],
      "states": {},
      "authors": ["string"],
      "cron": "string",
      "every": "10m",
      "timezone": "string",
      "from": ["string"],
      "label": "string",
      "history_id": "string",
      "history_account": "string",
      "agents": ["string"],
      "ended": ["completed"],
      "outcome": ["string"],
      "max_depth": 1
    },
    "next_fire_at": "2026-10-06T12:00:00Z",
    "last_fired_at": "2026-10-06T12:00:00Z",
    "created_at": "2026-10-06T12:00:00Z",
    "webhook_url": "https://example.com",
    "webhook_secret": "string"
  }
}
```
