# Notifications API

> Every /v1/notifications endpoint: send a notification.

Base URL: `https://api.nibify.app`.

## Send a notification

`POST /v1/notifications`

Creates an `informational` Message: it arrives on the phone, lands in the Inbox and is marked read when it is looked at, and asks for nothing back. There is no `pending` state, no expiry and no callback — what happens to it next reaches you as the `message.delivered` and `message.read` events of a webhook endpoint, if you subscribe to them. Send `surface` for a rich body; a surface that dispatches an action belongs to `POST /v1/requests` and is refused here. Send `threadKey` to say it inside a conversation you have already opened: the Message takes the next `sequence` of that Thread and stays `informational`, because it still asks for nothing.

**Headers**

| Field | Type | Description |
| --- | --- | --- |
| `Authorization` | string, required | `Bearer sk_test_…`: an API key of your project. |

**Request body**

| Field | Type | Description |
| --- | --- | --- |
| `sender` | object, required | Who the person sees the Notification as coming from. |
| `sender.name` | string, required | The name the person sees, free text. Not empty. |
| `sender.icon` | string | An icon for the sender, free text, kept and returned as sent. Nothing draws it: the person sees the sender by its `name`. Not empty. |
| `notification` | object, required | What the push says. |
| `notification.title` | string, required | The title of the push and of its Inbox row. Not empty. |
| `notification.body` | string, required | The text of the push and of its Inbox row. Not empty. |
| `priority` | string | How loudly the Notification announces itself: `low` only in the Inbox, `normal` with a push, `high` with a push that may break through the person’s quiet hours. One of `low`, `normal`, `high`. Defaults to `normal`. |
| `surface` | object | UI shown when the person opens the Notification, checked against the catalog. It may not dispatch an action: a Surface that asks for an answer is a Request. |
| `surface.root` | string, required | The `id` of the component the Surface is drawn from: always `root`, and one of `components` must carry it. Not empty. |
| `surface.dataModel` | object, required | The flat JSON state the components bind to by JSON Pointer, and the source of the values an action sends back. |
| `surface.components` | array of objects, required | The components, as a flat list, each one checked against the catalog. Not empty. |
| `threadKey` | string | Your name for a conversation: the Notification joins the Thread with this key, and asks for nothing there either. Without it, the Notification is a Thread of its own. 1 to 200 characters. |

**Example**

TypeScript:

```ts
import { Card, Column, Nibify, Text } from '@nibify/sdk';

const nibify = new Nibify({ apiKey: 'sk_test_…' });

const surface = {
  root: 'root',
  dataModel: {},
  components: [
    Card('root', { child: 'body' }),
    Column('body', { children: ['title', 'text'] }),
    Text('title', { text: 'Kiwi Studio invoice filed', variant: 'h4' }),
    Text('text', { text: '$1,420, consulting, due Oct 30.' }),
  ],
};

await nibify.notify({
  sender: { name: 'invoice-flow' },
  notification: {
    title: 'Kiwi Studio invoice filed',
    body: '$1,420, consulting, due Oct 30.',
  },
  surface,
});
```

curl:

```bash
curl -X POST https://api.nibify.app/v1/notifications \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "sender": { "name": "invoice-flow" },
    "notification": {
      "title": "Kiwi Studio invoice filed",
      "body": "$1,420, consulting, due Oct 30."
    },
    "surface": {
      "root": "root",
      "dataModel": {},
      "components": [
        { "id": "root", "component": "Card", "child": "body" },
        {
          "id": "body",
          "component": "Column",
          "children": ["title", "text"]
        },
        {
          "id": "title",
          "component": "Text",
          "text": "Kiwi Studio invoice filed",
          "variant": "h4"
        },
        {
          "id": "text",
          "component": "Text",
          "text": "$1,420, consulting, due Oct 30."
        }
      ]
    }
  }'
```

**Responses**

| Status | Description |
| --- | --- |
| `201` | The notification was created and is on its way. |
| `401` | [`unauthorized`](https://nibify.app/docs/errors-and-rate-limits#unauthorized) for a missing or unusable key, [`api_key_revoked`](https://nibify.app/docs/errors-and-rate-limits#api_key_revoked) for a revoked one. |
| `402` | [`plan_limit_reached`](https://nibify.app/docs/errors-and-rate-limits#plan_limit_reached). The Messages the account’s plan allows this month in this key’s Environment are spent — Requests and notifications together, across every Project of the account, counted from the first day of the month in UTC. `test` and `live` have a monthly allowance each, counted apart, so a spent `test` never refuses a `live` key, nor the other way round. The message names the Environment, the plan, its limit, the day the count starts again and where to upgrade. Nothing was created. Unlike a `429` there is no `Retry-After`: retrying is refused the same way until the month turns or the plan changes. |
| `422` | [`surface_invalid`](https://nibify.app/docs/errors-and-rate-limits#surface_invalid) names the component and property at fault, the `root` the renderer would not find, or a surface that dispatches an action — which is a Request and belongs to `POST /v1/requests`. [`invalid_request_body`](https://nibify.app/docs/errors-and-rate-limits#invalid_request_body) is a malformed envelope, and it is also what a field of a Request sent here gets: `quickActions`, `expiresAt` and `callbackUrl` are refused by name rather than ignored, because a notification that silently dropped a `callbackUrl` would leave an agent waiting for a call that is never made. |
| `429` | [`rate_limited`](https://nibify.app/docs/errors-and-rate-limits#rate_limited). This project is over its requests-per-second ceiling or its daily volume in the environment this key speaks for; the message says which of the two it was. The budget is the project’s and not the key’s, so another API key of the same project shares it — the `test` and `live` halves are counted apart. Nothing was created and nothing was counted: retrying after `Retry-After` is safe. Header `Retry-After`: how many seconds to wait before retrying. Always a whole number, never below 1. |

**Response body, 201**

| Field | Type | Description |
| --- | --- | --- |
| `messageId` | string, required | The Notification’s id, as the `message.delivered` and `message.read` events name it. |
| `threadId` | string, required | The Thread the Notification joined. |
| `sequence` | integer, required | The Notification’s position in its Thread, starting at 1. |
| `interactionType` | string, required | A Notification asks for nothing, in a Thread or out of one. Always `informational`. |
| `createdAt` | string, required | When the Notification was created. An RFC 3339 timestamp. |
| `environment` | string, required | The Environment of the API key that created it. One of `test`, `live`. |
| `minCatalogVersion` | integer or null, required | The lowest catalog version that can draw the Surface, worked out by the server. Null when there is no Surface. |
| `warnings` | array of objects, required | What did not stop the Message but changes how it is shown: `catalog_version_too_low` when no installed app can draw the Surface. |
| `warnings[].code` | string, required | What the warning is about, for a program to branch on. Always `catalog_version_too_low`. |
| `warnings[].message` | string, required | The same warning, in a sentence for a person. |
