# Coronium: notifications

An account keeps a list of what happened that its person or agent should know: a payment, a delivered or ending private line, a sign-in, a replaced credential, devices admitted or withheld, refused requests. An agent reads it with the session cookie a sign-in sets: step 2 of the agent instructions in [/guides/integrate.md](/guides/integrate.md). A credential is refused here with `session_required`. Both sites answer these calls for the same account.

Every path below is on the base URL you were given. The commands use curl and jq and the cookie file `coronium.cookies`.

## Read

`GET /app/api/notifications` answers the newest first. `unread` is the count of unread notifications, `mail` says whether the mailed kinds go to the account's confirmed address, and `next` is the cursor of the next page, or null. Each notification has `id`, `kind`, `firstAt`, `lastAt`, `count`, `read` and `data`. Add `?unread=true` for unread ones alone, and `cursor=<next>` for the next page; any other parameter is refused with `invalid`.

```
umask 077
BASE=${BASE:-https://coronium.ai}
curl -sS -b coronium.cookies "$BASE/app/api/notifications?unread=true" | jq '{unread, next, notifications: [.notifications[] | {id, kind, count, lastAt, data}]}'
```

A kind that counts its events keeps one notification for each reason and UTC day, so a whole fleet admitted in one day is one notification whose `count` is the number of devices; a device that moves back and forth counts once in each. A new event of a counted notification makes it unread again without moving it, so read `?unread=true` to find every unread one. A sign-in is listed already read. Refused requests are counted for a UTC day once it has ended and the edges' last counts have arrived. To read them all, follow `next` until it is null. Old notifications are deleted after a while, read or not: [/guides/limits.md](/guides/limits.md) says when.

## Mark read

`POST /app/api/notifications/read` takes exactly one of `{"id": "<id>"}`, which marks that notification, or `{"through": "<id>"}`, which marks it and every older one. It answers `marked` and the new `unread`. A repeat marks none. An id that is not one of this account's answers `notice_not_found`.

```
umask 077
BASE=${BASE:-https://coronium.ai}
newest=$(curl -sS -b coronium.cookies "$BASE/app/api/notifications" | jq -r '.notifications[0].id // empty')
[ -n "$newest" ] && jq -cn --arg id "$newest" '{through: $id}' | curl -sS -b coronium.cookies -H 'Content-Type: application/json' -d @- "$BASE/app/api/notifications/read"
```

## Mail

The kinds marked Mailed below are sent to the account's confirmed email address once per notification, not once per event it counts. A replaced credential is the exception: each replacement after the last mail ended is mailed again. `POST /app/api/notifications/mail` with `{"mail": false}` stops that, and `{"mail": true}` starts it again. Without a confirmed address nothing is mailed.

## Kinds

<!-- facts:begin notice.kinds -->
- `payment_credited`: A payment or a grant was added to your balance. Mailed.
- `payment_reversed`: A payment was reversed and taken from your balance. Mailed.
- `payment_failed`: A payment from an agent did not settle, and nothing was added. Mailed.
- `private_line_delivered`: An order of private lines was delivered. Mailed.
- `private_line_ending`: A private line ends soon. Mailed.
- `rotation_link_replaced`: A rotation link of a private line was replaced.
- `credential_replaced`: The account's credential was replaced. Mailed.
- `signed_in`: Someone signed in to this account.
- `device_admitted`: Devices were admitted and serve traffic.
- `device_withheld`: Devices were withheld and serve no traffic. Mailed.
- `requests_refused`: Requests of the account were refused yesterday.
- `balance_empty`: The balance is empty, so traffic stopped. Mailed.
<!-- facts:end notice.kinds -->

`data` holds integers as decimal strings and ids, never a secret: `usdMicros` and `source` or `cause` for a payment, `quoteId`, `orderId` with `lines` or `expiresAt`, `way` of a sign-in, `state` or `reason` of devices (the words of [/guides/device-states.md](/guides/device-states.md)), and `day` with `requests` for refused requests, whose codes `GET /app/api/usage/outcomes` lists.
