# Requests and notifications

> A Request waits for an answer and a Notification does not: two endpoints, and what each one accepts.

Your agent has two kinds of things to say to a person: what it needs an answer to, and what it only wants them to know. Kiwi Studio's invoice has both. Before filing it, `invoice-flow` asks; once it is filed, it says so. Nibify gives each its own endpoint.

## Two endpoints

Both create a Message: a sender, a notification block, the title and the line the lock screen shows, and optionally a Surface. Which endpoint you call decides what the Message is. Nothing in the body does.

- `POST /v1/requests` creates a **Request**. It is born `pending` and waits for the person's answer. In the SDK it is `ask()`.
- `POST /v1/notifications` creates a **Notification**. It asks for nothing. In the SDK it is `notify()`.

## A Request

The [Quickstart](https://nibify.app/docs/quickstart) sent one: the invoice, with **File it** and **Fix it** on the notification. The person answers, and the answer is the Request's Response: which action they chose, from which component, with what `context`.

A Request gets one Response and is never reopened. If the person changes their mind, your agent asks again, with a new Request.

Only a Request has a lifecycle: it is `pending` until it reaches one of four terminal states. Only a Request can expire, be withdrawn by your agent or be sent again as a reminder. [Lifecycle and expiry](https://nibify.app/docs/lifecycle-and-expiry) tells the whole story.

## A Notification

Once the person files the invoice, `invoice-flow` tells them it is done:

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."
        }
      ]
    }
  }'
```

It lands in the Inbox and rings the phone like a Request does, and nothing comes back. A Notification has no `pending`, no expiry and no Response. What there is to know about it is that it was delivered and that it was read, and those reach your agent as the `message.delivered` and `message.read` [webhook events](https://nibify.app/docs/webhook-events).

The `201` returns a `messageId` rather than a `requestId`, and `GET /v1/requests/{id}` does not know it.

A Notification may carry a Surface, to show more than a title and a line. The Surface may only show things: a button that sends an action is a question, so a Surface with one is refused with `422 surface_invalid`, and the error points at `POST /v1/requests`.

## What each one accepts

The two bodies share `sender`, `notification`, `surface`, `priority` and `threadKey`. Four things belong to a Request alone:

- `notification.quickActions`, the buttons on the notification.
- `expiresAt`, the moment the Request stops waiting.
- `callbackUrl`, an address called once, when the Request ends.
- The `Idempotency-Key` header, which [makes a retry safe](https://nibify.app/docs/idempotency-and-retries).

`POST /v1/notifications` refuses the three fields by name, with `422 invalid_request_body`, instead of ignoring them: a Notification that quietly dropped a `callbackUrl` would leave your agent waiting for a call that never comes.

It does not read an `Idempotency-Key`. The same Notification sent twice arrives twice, which is why the SDK's `notify()` never retries on its own.

Every field of both bodies is in the reference: the [Requests API](https://nibify.app/docs/rest/requests) and the [Notifications API](https://nibify.app/docs/rest/notifications).

## Next

- [Threads](https://nibify.app/docs/threads): One conversation per threadKey: how Messages are grouped, and what the person sees.
- [Lifecycle and expiry](https://nibify.app/docs/lifecycle-and-expiry): The states of a Request, the receipts of a Notification, and an expiry that happens only when you ask for one.
- [Requests API](https://nibify.app/docs/rest/requests): Every /v1/requests endpoint: list the Requests of this Project, create a Request, read a Request, withdraw a Request, re-notify a pending Request, await the outcome of a Request.
