# Notifications API

> Send notifications, read and set preferences, manage workspace notification settings, and read the delivery log over the REST API.

Source: https://docs.ligament.ai/developers/notifications/

The notification endpoints let your code read and change what people get, and let admins check what was sent. Every endpoint is in the [REST API reference](https://docs.ligament.ai/reference/rest-api/index.md) with its request and response shapes; this page explains how they fit together.

Calls use an API key (`Authorization: Bearer <key>`) or a signed-in session. Some endpoints act on “your own” settings and so need a signed-in user, not a key.

## Who can call what

| Endpoint | Credential | Who |
| --- | --- | --- |
| `GET /api/notifications`, `POST /api/notifications` (mark read) | Session | Anyone, for their own notifications |
| `GET`/`PUT /api/notifications/prefs` | Session | Anyone, for their own preferences |
| `/api/notifications/push-subscriptions…`, `GET /api/notifications/push/key` | Session | Anyone, for their own browsers |
| `GET`/`PUT /api/notifications/settings` | `settings:read` / `settings:write` | Owners and admins |
| `/api/notifications/connections…`, `/api/notifications/identities…` | `settings:read` / `settings:write` | Owners and admins |
| `GET /api/notifications/deliveries…`, `POST …/retry`, `GET /api/notifications/action-log` | `settings:read` / `settings:write` | Owners and admins |
| `POST /api/notifications/preview` | `settings:read` | Owners and admins |
| `GET`/`PUT /api/notifications/rules` | `settings:read` / `settings:write` | Owners and admins (team channels) |

A key acts with its creator’s role, so a key made by a member gets `403` from the admin endpoints even with the right scope.

The `/api/notify/…` endpoints (`actions`, `slack/interactions`, `teams/messages`, `push/receipt`, `twilio/status/{id}`) are called by Slack, Microsoft Teams, browsers and Twilio. Each checks a signature from the caller and isn’t meant for your code.

## Preferences

`GET /api/notifications/prefs` returns the caller’s preferences together with what the page needs to show them: the channels available, the admin defaults that apply, the events that are urgent, the workspace time zone, linked Slack/Teams accounts and push devices.

`PUT /api/notifications/prefs` replaces them:

```json
{
  "prefs": {
    "events": {
      "approval": { "inapp": "instant", "email": "instant", "plugin:slack": "instant" },
      "comment": { "email": "digest" }
    },
    "addresses": { "sms": "+66812345678" },
    "digest": { "cadence": "daily", "hour": 8 },
    "timezone": "Asia/Bangkok",
    "quiet": { "enabled": true, "start": "22:00", "end": "07:00" }
  }
}
```

Modes are `instant`, `digest` and `off`. A mode above an admin cap is stored but never applied: the effective mode is the lower of the two.

## Workspace settings

`GET`/`PUT /api/notifications/settings` reads or replaces the admin settings:

```json
{
  "settings": {
    "defaults": { "approval": { "email": { "mode": "instant", "userMay": "narrow" } } },
    "events": {
      "sla_breach": { "urgent": true },
      "approval": { "bodyMode": "minimal", "escalation": { "afterHours": 8, "to": "manager" } }
    },
    "rateLimits": { "sms": 20 },
    "templates": { "approval": { "*": { "title": "Approval: {{record.label}}", "body": "Please review." } } }
  }
}
```

-   `defaults[event][channel].userMay`: `narrow` (people may only lower it) or `any`.
-   `events[event].bodyMode`: `minimal` (the default, except `workflow_message`: `full`), `full` or `template`. Whatever the mode, values the recipient can’t read are removed. See [Workspace notification settings](https://docs.ligament.ai/guides/notifications/admin/index.md#fields-people-cant-see-never-leave).
-   `events[event].escalation`: `afterHours` and `to` (`manager`, or `channel` with a `channelId`).
-   `rateLimits[channel]`: messages per minute for the workspace. `0` means no limit.
-   `templates[event][channel]`: `*` applies to every channel outside the app.

`POST /api/notifications/preview` renders a message the way a channel sends it, **as the caller**, with the caller’s field access: `{ "eventType": "approval", "channelId": "plugin:slack", "mode": "template", "entityKey": "hr_leave_request", "recordId": "…" }`. It returns the message, its plain text, the email HTML and the channel’s own format (Slack blocks, a Teams card, a push payload). There is no way to preview as someone else.

## Delivery log

`GET /api/notifications/deliveries` lists deliveries, newest first. One row is one message to one address on one channel. Filter with `status` (a comma list of `pending`, `held`, `sending`, `sent`, `delivered`, `failed`, `dead`), `channel`, `event`, `recipient` (a user id) and `eventId`. Page with `limit` (up to 200) and `before` (the `next` value of the previous page). The response also has `counts` per status for the whole workspace.

`GET /api/notifications/deliveries/{id}` returns one delivery with the message, its history (`queued`, `held`, `rate_limited`, `sent`, `delivered`, `failed`, `retry`, `dead`, `manual_retry`, `clicked`, `action`, `suppressed`) and any button presses on it.

The list masks email addresses and phone numbers (`l•••@example.com`, `+668•••02`); the single delivery shows them in full. Each copy was written for its recipient. When you read someone else’s copy, its title and text are masked again for **you**: values you can’t read on the record are replaced with `•••••`, and if you can’t open the record you get only the event’s kind.

`POST /api/notifications/deliveries/{id}/retry` queues a `failed` or `dead` delivery again (`409` for any other status).

`GET /api/notifications/action-log` lists button presses from messages (Approve, Reject): who pressed (the member, or the Slack or Teams user when unlinked), on which channel, and the outcome (`done`, `already`, `refused`, `expired`, `unmapped`, `invalid`, `error`).

## Sending a notification

`POST /api/notifications` doesn’t send messages; it marks the caller’s in-app notifications read. Notifications are sent by Ligament itself: approvals, assignments, comments, SLA timers, escalations, team channel rules and your workflows’ notify steps. They go through preferences, quiet hours, redaction and the delivery log.

## Notify from a workflow

A workflow sends a message with its `notify` step: the `notify` action in a workflow definition, or `ctx.notify` in a code workflow. The message is a notification like any other, of the kind **Workflow message**:

-   **Who.** `to` takes one or more email addresses or member user ids, separated by commas. A member is reached on their own channels, as their preferences and your workspace defaults say. Workflow messages go to the bell and by email until someone changes that. An address that isn’t a member’s gets an email.
-   **When.** Quiet hours hold every channel except in-app until the window ends, unless an admin marked **Workflow message** as urgent.
-   **What.** Each copy is written for its reader. The message is about a record: the record that started the workflow, or the one the step names (`entity` and `recordId`, or `entityKey` and `recordId` in `ctx.notify`). In the app, the reader gets your subject and text, with every value of that record they can’t read replaced by `•••••`. Outside the app (email, Slack, Teams, push, SMS), they get your text too, with the same values removed, unless an admin set **Workflow message** to **Minimal** (the event and the record’s name with a link) or **Template**. Someone who can’t open the record gets only “New workflow message” and the link.
-   **Where it shows.** Every copy is in the [delivery log](#delivery-log), and failed sends are retried.
-   **Once.** A step sends its message once per run, however often the step is retried or replayed.

```ts
await ctx.notify({
  id: 'tell-manager',
  to: managerEmail,
  subject: `Salary change: ${employee.name}`,
  message: `${employee.name} now earns ${employee.salary.amount} ${employee.salary.currency}.`,
  // optional: entityKey + recordId (default: the run's trigger record), channel ('email' or 'inapp'), integration
})
```

```json
{ "id": "tell", "kind": "action", "action": "notify",
  "params": { "to": "{{trigger.record.owner}}", "channel": "inapp",
              "subject": "Quiet sign-up: {{trigger.record.name}}", "body": "No API call in 3 days." } }
```

`channel` limits the message to `email` or `inapp`. Without it, each person’s own routing decides. The step’s output says what happened: `{ notified, queued, held, digest }`, plus `duplicate: true` when an earlier attempt of the same step already sent it and `unresolved` for addressees that are neither an email address nor a member.

Only values of the record the message is about are checked. If your text quotes another record (a lookup step’s output, say), name that record in the step or leave those values out. To send a full email to someone outside the workspace, such as a customer, use the `email.send` action with an email template.

To call another system rather than a person, see [Webhooks or notifications?](https://docs.ligament.ai/developers/webhooks-vs-notifications/index.md).

## Related

-   [Your notifications](https://docs.ligament.ai/guides/notifications/index.md)
-   [Workspace notification settings](https://docs.ligament.ai/guides/notifications/admin/index.md)
-   [Connect Slack and Microsoft Teams](https://docs.ligament.ai/guides/notifications/slack-teams-setup/index.md)
-   [API scopes](https://docs.ligament.ai/reference/scopes/index.md)
