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

# Notification API and data model

> The notification API for integrations and for the module, with the permission of each route, and the tables that store events, templates, occurrences, sends, preferences and suppressions.

## What it is for

This page is for teams that integrate with notifications or read their data: how an integration sends, which
routes the module uses and with which permission, and what each table holds. It replaces the old "Preferences &
Inbox" page, which now redirects here; preferences and the inbox are covered in the routes and tables below.

## Sending from an integration

An external system sends with `POST /api/v3/notification` and an API key.

| Requirement | Detail |
| - | - |
| Flag | `notification-api` must be on; otherwise the answer is "403 feature-disabled" |
| Permission | `notification:send`; raw content (no template) also needs `notification:send-raw` |
| Gateway | The API key may only use the gateways linked to it; each gateway is an idempotency scope |
| Size | Up to 100 items per request; all are validated before any is accepted (422 if one fails, 403 for permissions) |
| Event items | `{ "type": "event", … }` fire a catalog event through the same engine as Horizon's flows; the event must be linked to the gateway |
| Idempotency | `external_id` is unique per gateway: repeating it returns the first send |
| Account of an event item | `recipients.account` (the account id) **or** `recipients.dni` + `recipients.type_dni` (the identity document, never both). `type_dni` is the document type code, for example `CHL_RUT` or `CHL_PASSPORT`, never an id. A RUT goes with or without dots |
| Scheduling link of the maintenance events | `data.url` may be left out when the flag `notification-contactability-scheduling-link` is on: Horizon then puts a 14-day portal link that signs the account owner in on Schedule maintenance. With the flag off a missing `url` answers 422 `invalid-data` (`data.url`). The occurrence stores `url` as `[redacted]` |
| Delivery states | The integration learns what happened to each channel through the outbound webhooks: `notification.delivered`, `opened`, `clicked`, `bounced`, `complained`, `failed` and `skipped`, each with the `idempotency_key` it sent, the event key, the channel, the occurrence and the gateway in `data.object`. Its webhook is global and limited to its gateway with `notification_gateway`, so it never sees another integration's sends ([Event catalogue](https://docs.bbrands.io/webhooks/event-catalogue.md#notification), [Subscriptions](https://docs.bbrands.io/webhooks/subscriptions.md#limit-to-a-notification-gateway)) |

Example: an event item that names the customer by RUT, sent with the `x-api-key` header.

```json theme={null}
{
  "notifications": [
    {
      "type": "event",
      "event": "maihue.maintenance-scheduling.unreachable-first-reminder-due",
      "data": { "phone": "+56 9 1234 5678", "url": "https://maihue.setmore.com/" },
      "recipients": { "dni": "12.345.678-5", "type_dni": "CHL_RUT" },
      "idempotency_key": "MNT-12345:unreachable-1"
    }
  ]
}
```

| Answer | When |
| - | - |
| 422 `account-not-found` | No account has that document |
| 422 `account-ambiguous` | The document matches more than one account |
| 422 `type-dni-unknown` | `type_dni` is not a known document type code |
| 422 `invalid-data` (`recipients.dni`) | The RUT check digit is wrong, or `account` and `dni` come together |
| 422 `invalid-data` (`recipients.type_dni`) | `dni` comes without `type_dni` (and `recipients.dni` when `type_dni` comes alone) |
| 422 `recipient-unreachable` | The account found has no login with an email to write to |
| 422 `invalid-data` (`data.url`) | A maintenance scheduling event without `url` while `notification-contactability-scheduling-link` is off |

Each call creates a **request** that groups its sends and counts accepted, duplicated and rejected items.
`POST /api/v3/notification/dispatch` is deprecated: it answers with `Deprecation` and `Sunset` headers and only
accepts the portal onboarding welcome.

## Routes of the module

All routes are under `/api/v3/notification`.

| Area | Routes | Permission |
| - | - | - |
| Sends | `GET /`, `GET /{id}`, `GET /{id}/event` | `notification:find-all`, `notification:find-one` |
| Send content | `GET /{id}/content` | `notification:view-content` |
| Send actions | `POST /{id}/cancel`; `POST /{id}/retry`, `POST /{id}/resend` | `notification:cancel`; `notification:resend` |
| Occurrences | `GET /occurrence`, `GET /occurrence/{id}` | `notification-occurrence:find-all`, `:find-one` |
| Delivery events | `GET /event` | `notification-event:find-all` |
| Event catalog | `GET /catalog/event`, `GET /catalog/event/{id}`, `GET …/history`; `PATCH /catalog/event/{id}` (only `bypass` and `change_reason`; `is_actived` answers 422: an event is not turned off by hand), `PATCH …/channel/{channel}` (`is_actived`, rules) | `notification-event-catalog:find-all`, `:find-one`; `:update` |
| Channel contract | `GET /channel/{channel}/contract` | `notification-template:find-all` |
| Templates | `GET /template`; versions `GET`, `POST`, `PUT`, `DELETE`; `POST …/preview`; `GET …/diff/{other}`; `POST …/test-send`; `POST …/publish` | `notification-template:find-all`, `:find-one`, `:edit`, `:test-send`, `:publish` (or `:publish-marketing` for marketing events) |
| Preferences (staff) | `GET`, `POST`, `PUT /preference`; `GET`, `PATCH`, `DELETE /preference/{id}`; `PATCH …/active`; `DELETE …/purge` | `notification-preference:find-all`, `:create`, `:update`, `:find-one`, `:delete`, `:active`, `:purge` |
| Own preferences | `GET`, `PUT`, `PATCH /preference/me` | `notification-preference:read-own`, `:update-own` |
| Unsubscribe link | `GET`, `POST /preference/unsubscribe` | Public, with the signed token of `{{links.preferences}}` |
| Suppressions | `GET /suppression`; `POST`, `DELETE /suppression`, `DELETE /suppression/{id}` | `notification-suppression:find-all`; `:update` |
| Rates | `GET /rate`; `POST /rate` | `notification-rate:find-all`; `:update` |
| Gateways | `GET /gateway` | `notification-gateway:find-all` |
| Requests | `GET /request`, `GET /request/{id}` | `notification-request:find-all`, `:find-one` |
| Dashboard | `GET /dashboard`, `GET /metric` | `notification:dashboard` |
| Inbox (own) | `GET /inbox/me` (`page`, `page_size`, `unread=true` or `read=true`), `GET /inbox/me/unread-count`; `PATCH /inbox/me/{id}/read`, `/read-all`, `/seen` | `notification-inbox:read`; `notification-inbox:update` |
| Exports | `POST /export`, `POST /event/export`, `POST /preference/export` | `<entity>:export` |

The webhooks of the providers are in [Providers and webhooks](https://docs.bbrands.io/enterprise/notifications/reference/providers.md);
which role holds each permission is in [Roles and permissions](https://docs.bbrands.io/enterprise/notifications/getting-started/roles-and-permissions.md).

> [!NOTE]
>
> The own-preference routes take the user from the session and refuse to turn off a category that cannot be turned
> off. They never accept another user.

> [!NOTE]
>
> `POST /{id}/retry` and `POST /{id}/resend` check the send again before writing anything: an inactive event or
> channel, a suppressed address or an opt-out answers `409` with the code `notification-not-eligible` and the
> decision reason in `reason`. Quiet hours, the frequency cap and the time to live do not apply.

## Data model

| Table | What it holds |
| - | - |
| `notification_event` | The catalog: one row per declared event, written by migration |
| `notification_event_channel` | The event's channels: on or off, quiet hours, cap, delay, fallback |
| `notification_event_gateway` | External gateways allowed to fire the event |
| `notification_gateway` | Origins that may send: Horizon itself (`system`) or an integration (`external`) |
| `notification_template` | One template per event and channel |
| `notification_template_version` | Its versions (draft, published, archived) with the fields shared by every language |
| `notification_template_language` | The text of a version in one language |
| `notification_template_gateway` | Limits a template to some gateways |
| `notification_occurrence` | Each firing of an event: data (sensitive fields redacted), subject, origin, keys, status |
| `notification_occurrence_decision` | One decision per channel, recipient and fallback: outcome, reason, language, deferred time |
| `notification_request` | One API call or internal batch, with its counters |
| `notification` | One row per send: channel, status, recipient, provider, cost, links to occurrence, template version and request |
| `notification_email`, `notification_push`, `notification_sms`, `notification_live_activity`, `notification_in_app`, `notification_whatsapp` | The channel content of each send; `notification_in_app` is the inbox item with `seen_at` and `read_at` |
| `notification_email_attachment` | Email attachments, by reference |
| `notification_<channel>_event` | Provider and Horizon events of each send, unique per provider event |
| `notification_preference` | Opt-out overrides per user or account, category or event; no row means "on" |
| `notification_suppression` | Blocked addresses, stored as a keyed hash plus a masked copy, with reason and who lifted them |
| `notification_channel_rate` | The price of a send per channel, provider and country, valid from a date |
| `notification_metric_hourly`, `notification_metric_daily` | Dashboard figures |

```text theme={null}
notification_event ─┬─ notification_event_channel
                    ├─ notification_template ── notification_template_version ── notification_template_language
                    └─ notification_occurrence ── notification_occurrence_decision
                                                        │
notification_request ─── notification ◄─────────────────┘
                          ├─ notification_<channel>        (content, 1:1)
                          └─ notification_<channel>_event  (timeline, 1:n)
```

The full column reference of each table is in the **Schemas** tab, starting at [`notification`](https://docs.bbrands.io/schemas/notification/notification).

## Technical detail

| Aspect | Detail |
| - | - |
| Routes | `backend/horizon-api/app/api/v3/notification/**` |
| Intake and validation | `backend/horizon-api/lib/notification/core/notification-intake.ts` |
| Retry and resend | `backend/horizon-api/lib/notification/resend/notification-resend.service.ts` |
| API key gateways | `api_key_notification_gateway` (permission schema) |
| Tables | `database/horizon-drizzle/database/schemas/(notification)/**` |
| Retention | Inbox items 180 days (purged at 365); sends, events, occurrences and decisions 13 months; email HTML 180 days |

## Related and history

* [Architecture](https://docs.bbrands.io/enterprise/notifications/reference/architecture.md)
* [Providers and webhooks](https://docs.bbrands.io/enterprise/notifications/reference/providers.md)
* [Roles and permissions](https://docs.bbrands.io/enterprise/notifications/getting-started/roles-and-permissions.md)

| Date | Change |
| - | - |
| 2026-11-11 | First version, rewritten from the old "Preferences & Inbox" page, which now redirects here |
| 2026-11-12 | `GET /inbox/me` filters read items with `read=true` (full staff inbox, #2137) |
| 2026-11-12 | Retry and resend answer `409 notification-not-eligible` when the send is no longer allowed (issue #2203) |
| 2026-11-20 | `PATCH /catalog/event/{id}` accepts only `bypass` and `change_reason`; `is_actived` answers 422 (D-92) |
| 2026-11-23 | Event items may name the account by identity document (`dni` + `type_dni`, contactability-events D-17) |
| 2026-11-23 | `url` of the maintenance scheduling events is optional behind `notification-contactability-scheduling-link` (contactability-events REQ-09) |
| 2026-11-23 | Delivery states back to the integration through outbound webhooks, limited to its gateway (contactability-events REQ-10) |


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