# Routines

> Standing work on a schedule, once, on an event (email, webhook, app event) or until a goal is met; run history: 11 endpoints of the Teemli API.

Source: https://docs.teemli.com/developers/reference/routines/

Generated from [`api/openapi.yaml`](/developers/api/) (OpenAPI 3.1). Base URL: `https://api.teemli.com`. Auth: `Authorization: Bearer <token or tml_ API key>`. Errors are `application/problem+json`; writes accept an `Idempotency-Key` header.

Standing work on a schedule, once, on an event (email, webhook, app event) or until a goal is met; run history

## My routines (and those of AI employees I manage)

```http
GET /v1/orgs/{org}/routines
```

**API keys:** needs the `agents:read` scope.

| Parameter | In | Type | Description |
|---|---|---|---|
| `org` (required) | path | string (uuid) | The caller's organisation id. |
| `agent_id` | query | string (uuid) |  |
| `status` | query | `active`, `paused`, `completed`, `all` | Default: everything but disabled |

**Responses**

- `200` Routines, newest first — object
- `401` Missing, invalid or expired token — Problem

## Create a routine with the form (no confirm card — it's the person's own act)

```http
POST /v1/orgs/{org}/routines
```

Validated as a whole: cron in the routine's time zone (default the person's), at least
`TEEMLI_ROUTINE_MIN_INTERVAL_MINUTES` apart; caps per person and per agent. Agents propose routines
with routine.create instead, which the person confirms on a setup_change card. Webhook routines
return `webhook_url` with its secret once.

**API keys:** needs the `agents:write` scope.

| Parameter | In | Type | Description |
|---|---|---|---|
| `org` (required) | path | string (uuid) | The caller's organisation id. |

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `agent_id` (required) | string (uuid) |  |
| `title` | string |  |
| `instructions` | string | What to do on each run (each run is a new task) |
| `trigger` | `schedule`, `once`, `event`, `goal` |  |
| `cron` | string \\| null | schedule: five-field cron in time_zone, e.g. "0 9 * * 1-5" |
| `schedule_text` | string \\| null | Plain words shown to people, e.g. "Every weekday at 9:00" |
| `run_at` | string \\| null | once: local "YYYY-MM-DD HH:MM" in time_zone, or RFC 3339 |
| `time_zone` | string \\| null | IANA; default the person's |
| `event_source` | `email`, `webhook`, `composio`, `null` | Slack/Teams phrases arrive with M5 |
| `composio_trigger` | string \\| null |  |
| `connection_id` | string \\| null (uuid) | event/composio: which account |
| `event_filter` | object \\| null | Composio trigger config |
| `goal` | string \\| null | goal: what done looks like |
| `check_every_minutes` | integer \\| null | goal: default 60 |
| `give_up_after_days` | integer \\| null | goal: default 14 |
| `deliver_to` | `task`, `conversation`, `null` | task (default) or also post the result in the agent's chat |

**Responses**

- `201` Created — object
- `401` Missing, invalid or expired token — Problem
- `404` Not found (also returned for rows the caller may not see, and for disabled features) — Problem
- `422` Invalid input — Problem

## One routine

```http
GET /v1/orgs/{org}/routines/{routine}
```

**API keys:** needs the `agents:read` scope.

| Parameter | In | Type | Description |
|---|---|---|---|
| `org` (required) | path | string (uuid) | The caller's organisation id. |
| `routine` (required) | path | string (uuid) |  |

**Responses**

- `200` The routine — Routine
- `401` Missing, invalid or expired token — Problem
- `404` Not found (also returned for rows the caller may not see, and for disabled features) — Problem

## Change fields (validated as a whole), or pause/resume (`status`)

```http
PATCH /v1/orgs/{org}/routines/{routine}
```

Resuming recomputes the next run and clears the failure count.

**API keys:** needs the `agents:write` scope.

| Parameter | In | Type | Description |
|---|---|---|---|
| `org` (required) | path | string (uuid) | The caller's organisation id. |
| `routine` (required) | path | string (uuid) |  |

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `status` | `active`, `paused` |  |
| `title` | string |  |
| `instructions` | string | What to do on each run (each run is a new task) |
| `trigger` | `schedule`, `once`, `event`, `goal` |  |
| `cron` | string \\| null | schedule: five-field cron in time_zone, e.g. "0 9 * * 1-5" |
| `schedule_text` | string \\| null | Plain words shown to people, e.g. "Every weekday at 9:00" |
| `run_at` | string \\| null | once: local "YYYY-MM-DD HH:MM" in time_zone, or RFC 3339 |
| `time_zone` | string \\| null | IANA; default the person's |
| `event_source` | `email`, `webhook`, `composio`, `null` | Slack/Teams phrases arrive with M5 |
| `composio_trigger` | string \\| null |  |
| `connection_id` | string \\| null (uuid) | event/composio: which account |
| `event_filter` | object \\| null | Composio trigger config |
| `goal` | string \\| null | goal: what done looks like |
| `check_every_minutes` | integer \\| null | goal: default 60 |
| `give_up_after_days` | integer \\| null | goal: default 14 |
| `deliver_to` | `task`, `conversation`, `null` | task (default) or also post the result in the agent's chat |

**Responses**

- `200` The routine — Routine
- `401` Missing, invalid or expired token — Problem
- `404` Not found (also returned for rows the caller may not see, and for disabled features) — Problem
- `422` Invalid input — Problem

## Delete (app-event routines also unsubscribe)

```http
DELETE /v1/orgs/{org}/routines/{routine}
```

**API keys:** needs the `agents:write` scope.

| Parameter | In | Type | Description |
|---|---|---|---|
| `org` (required) | path | string (uuid) | The caller's organisation id. |
| `routine` (required) | path | string (uuid) |  |

**Responses**

- `204` Deleted
- `401` Missing, invalid or expired token — Problem
- `404` Not found (also returned for rows the caller may not see, and for disabled features) — Problem

## Run now (a new task; the schedule is unchanged)

```http
POST /v1/orgs/{org}/routines/{routine}/run
```

**API keys:** needs the `agents:run` scope.

| Parameter | In | Type | Description |
|---|---|---|---|
| `org` (required) | path | string (uuid) | The caller's organisation id. |
| `routine` (required) | path | string (uuid) |  |

**Responses**

- `202` Started — open the task — object
- `401` Missing, invalid or expired token — Problem
- `403` Authenticated but not allowed (e.g. unverified email, not the agent's controller, card routed to someone else) — Problem
- `404` Not found (also returned for rows the caller may not see, and for disabled features) — Problem

## Run history, newest first (each run is a task; skipped = over the event cap)

```http
GET /v1/orgs/{org}/routines/{routine}/runs
```

**API keys:** needs the `agents:read` scope.

| Parameter | In | Type | Description |
|---|---|---|---|
| `org` (required) | path | string (uuid) | The caller's organisation id. |
| `routine` (required) | path | string (uuid) |  |
| `limit` | query | integer | Page size. |
| `cursor` | query | string | Opaque cursor from a previous page's `next_cursor`. |

**Responses**

- `200` Runs — object
- `401` Missing, invalid or expired token — Problem
- `404` Not found (also returned for rows the caller may not see, and for disabled features) — Problem

## New webhook secret (the old URL stops working); the URL is shown only now

```http
POST /v1/orgs/{org}/routines/{routine}/webhook-secret
```

**API keys:** needs the `agents:write` scope.

| Parameter | In | Type | Description |
|---|---|---|---|
| `org` (required) | path | string (uuid) | The caller's organisation id. |
| `routine` (required) | path | string (uuid) |  |

**Responses**

- `200` The webhook URL — object
- `401` Missing, invalid or expired token — Problem
- `404` Not found (also returned for rows the caller may not see, and for disabled features) — Problem

## Run a webhook routine (anything ≤ 64 KB; it reaches the agent as outside content)

```http
POST /v1/hooks/routines/{routine}/{secret}
```

**Auth:** none (public endpoint).

| Parameter | In | Type | Description |
|---|---|---|---|
| `routine` (required) | path | string (uuid) |  |
| `secret` (required) | path | string |  |

**Responses**

- `202` Accepted (`accepted: false` when the routine is paused) — object
- `404` Unknown routine or wrong secret

## Run a webhook routine, with the secret in a header (for senders that can set one)

```http
POST /v1/hooks/routines/{routine}
```

Same as the path form; the secret goes in `X-Teemli-Webhook-Secret` or `Authorization: Bearer`.

**Auth:** none (public endpoint).

| Parameter | In | Type | Description |
|---|---|---|---|
| `routine` (required) | path | string (uuid) |  |
| `X-Teemli-Webhook-Secret` | header | string |  |

**Responses**

- `202` Accepted (`accepted: false` when the routine is paused) — object
- `404` Unknown routine or wrong secret

## Composio trigger events (Standard Webhooks signature with the project secret)

```http
POST /v1/hooks/composio
```

**Auth:** none (public endpoint).

**Responses**

- `202` Accepted
- `401` Bad signature
- `404` Not configured (COMPOSIO_WEBHOOK_SECRET unset)
