# Ingat API v1

Base URL: `https://ingat.ingatbiz.com` (local: `http://localhost:3000`).
Every route except `/health` needs `Authorization: Bearer ingat_dev_…`.
Times are ISO 8601 with an offset or `Z`. Phone numbers may be sent in local
form (`0812…`) and are returned as E.164 (`+62812…`).

## Devices

Tokens are issued on the server only, and shown once:

```bash
node dist/cli/device-cli.js issue "Yungki iPhone" IOS     # IOS | IPADOS | MACOS | ANDROID
node dist/cli/device-cli.js list
node dist/cli/device-cli.js revoke <device-id>
```

| Method | Path | Purpose |
| --- | --- | --- |
| GET | `/api/v1/devices/me` | The calling device |
| PATCH | `/api/v1/devices/me` | Set `name` or `pushToken` |
| GET | `/api/v1/devices` | All devices |
| POST | `/api/v1/devices/:id/revoke` | Revoke another device, e.g. a lost phone |

## Accounts

Every device token belongs to one account (a customer). All routes below only ever see that account's data. The same WhatsApp number may be a person in several accounts.

| Method | Path | What it does |
|---|---|---|
| GET | `/api/v1/accounts/me` | The account's settings plus `usage` (`includedPerMonth`, `usedThisMonth`, `balance`, `available`, `planActive`) and `limits` (all `-1`: memberships differ only by reminders a month, see Pricing), plus `accountPageUrl`, where memberships are bought (null when `PURCHASE_LINK_IN_APPS=false`, for store review). A reminder is paid for when sent, one per person per lead time, from the month's included allowance first, then the balance; otherwise the delivery waits as `HELD` with `lastError: NO_BALANCE` |
| PATCH | `/api/v1/accounts/me` | Change `name`, `language`, `timezone` (an IANA zone such as `Asia/Jakarta`; anything else is `400`), `requireOptIn`, `defaultLeadTimesMinutes` (what a new reminder starts with for "when to remind" in the apps), or `followUpAfterMinutes` (send a reminder once more when a person has not replied this many minutes after it was due, `0` = at the due time, `null` = off; one follow-up per person per occurrence, which counts as a reminder; the follow-up delivery carries `followUp: true` and the message says "(follow-up)") |
| POST | `/api/v1/auth/apple` | Public. Body `{ identityToken, name?, deviceName, platform }` from Sign in with Apple. Creates the account on first use and answers `{ account, device, token }`; the token is the device token used everywhere else |
| POST | `/api/v1/auth/google` | Public. Body `{ idToken, deviceName, platform }` from Sign in with Google (Android). Same answer. A verified Google e-mail that already belongs to an account joins that account, so one person can use an iPhone and an Android phone together. Needs `GOOGLE_CLIENT_IDS` on the server. Optional `nonce`: a random value the app gave Google for this sign-in; when sent, the token must carry it |

### Self reminder from the calendar

The owner's device shares the calendar events it sees; the server reminds the owner, and, with `agendaInviteAttendees: true` on the account (`PATCH /api/v1/accounts/me`), also the attendees who are in People: each event may carry `attendees: [{ name?, email? }]`, matched to people by `email` first, then by an exact name or alias (case-insensitive). People who said STOP are never added. Attendees not in People are never messaged. Settings live on the account (`PATCH /api/v1/accounts/me`): `agendaMode` `OFF` | `DAILY` (one message with tomorrow's agenda; when tomorrow is empty, the next day with meetings within a week, once) | `EACH` (one reminder per meeting) | `BOTH`, `agendaTimeMinute` (when the daily digest goes, minute of the day in the account's time zone; 1140 = 19:00) and `agendaLeadMinutes` (how long before each meeting). The daily message lists each meeting on its own lines (time, title, place). When the owner wrote to Ingat within the last 24 hours it goes as a plain WhatsApp message in that layout (the reminder's `notes`); otherwise through Ingat's `lib_agenda_<n>_v2` templates (1–6 meetings; more are counted on the last line); until Meta approves them, a one-line version goes through the task template. Each delivery also carries `nextAttemptAt`: when it is later than `fireAt` the message is waiting for the person's quiet hours to end (or a retry). Reminders made this way have `source: CALENDAR`; the digest's `externalId` is `agenda:<date>`, a meeting's is `cal:<event id>`.

| Method | Path | What it does |
|---|---|---|
| PUT | `/api/v1/agenda/events` | App only. Body `{ from, to, events: [{ externalId, title, startAt, endAt, allDay?, location?, calendarName? }] }` (≤ 500). Replaces the account's events whose start falls in `[from, to)`; events outside the window are untouched. In `EACH` mode, reminders are created, updated and cancelled to match. Each device replaces only what it shared itself; the account's agenda is the union of its devices, so a phone that sees fewer calendars (or none) never removes what the Mac shared, and a meeting is dropped only when no device sees it. In EACH/BOTH mode each timed event becomes its own reminder sent as the Meeting template (title, place, time), never merged with other reminders |

### Admin (operator only)

`GET /api/v1/accounts/me` carries `isAdmin`; it is true only for the operator's own account (set on the server with `account-cli admin <name> on`). For that account, from the app only (never an API key):

| Method | Path | What it does |
|---|---|---|
| GET | `/api/v1/admin/accounts` | Every account with `ownerName` and `ownerNumber` (what the user entered in the app), `plan`, `status`, `devices`, `lastSeenAt`, `people`, `reminders`, `messagesThisMonth`, `messagesAllTime`, `failedThisMonth`, `lastMessageAt`, `reminderBalance` (left) and `remindersUsed` (consumed from the balance, all time), plus `totals` |
| GET | `/api/v1/admin/support.csv` | The same inbox as a CSV file (`User`, `WhatsApp number`, `Account`, `Membership`, `Sent at`, `Question`, `Status`, `Reply`, `Replied at`), newest first |
| GET | `/api/v1/admin/support` | Questions users sent from Help (`text`, `status` OPEN/ANSWERED, `accountName`, `fromName`, `fromNumber`, `reply`), open first |
| POST | `/api/v1/admin/support/:id/reply` | Body `{ text }`. Stores the reply, shown under Help on the user's devices. Replies are never sent on WhatsApp (`replySentOnWhatsApp` is always false) |
| GET | `/api/v1/admin/accounts/:id` | The same row plus `months` (last six: `sent`, `failed`, `replies`), `deviceList` and reminder `outcomes` |
| GET | `/api/v1/admin/pricing` | The membership parameters: for Basic (`INDIVIDUAL`), `TEAM` and `BUSINESS` the `label`, `includedPerMonth`, `priceIdr`, `blockSize` and `blockPriceIdr` |
| PUT | `/api/v1/admin/pricing/:plan` | Changes any of those fields. Metering follows within seconds: an account on that membership without an allowance of its own may send `includedPerMonth` reminders a month |
| GET | `/api/v1/admin/coupons` | Every coupon, newest first, with `redemptions` |
| POST | `/api/v1/admin/coupons` | `{ kind: FREE_REMINDERS \| MONEY_OFF \| PERCENT_OFF, value, plan?, maxRedemptions?, expiresAt?, note?, code? }`. Makes a code such as `INGAT-7KQ2-M9XA` (or uses `code`, upper-cased). Share the code with the user |
| PATCH | `/api/v1/admin/coupons/:id` | `{ active }` switches a code off or on |

Every device can read `GET /api/v1/pricing` (the same memberships, for the paywall) and redeem a code with `POST /api/v1/coupons/redeem { code }`. Free reminders go on the balance at once and release held reminders; a money or percent discount waits on the account (`discount` on `GET /accounts/me`) for the next subscription payment. Each account may use a code once; `409` when used up, expired, already used, or for another membership; `404` when unknown or switched off.

Message counts are WhatsApp messages Meta accepted (templates and buttons); free-form replies are listed separately. Every other account gets 404 from these routes, as if they did not exist.

### Notices to the owner

The scheduler tells the account's owner on WhatsApp, once each and never in their quiet hours: when the membership ends in three days, when it has ended, and when ten or fewer reminders can still be sent this month (said again only after the balance recovered and dipped again). Notices go through the reminder template from "IngatBiz" with the account page link, and are not taken from the balance.

Also for the operator: `GET /api/v1/admin/orders.csv` with the same filters as `/admin/orders` (a spreadsheet of payments), and `GET /api/v1/admin/delivery-health?days=7` (1–90): WhatsApp messages Meta accepted in the window, deliveries that failed, how many wait for balance, the failures grouped by reason in words (Meta's code in brackets) with a count, how many accounts and an example, and accepted/failed per day.

## Account page (website)

The account page at `https://www.ingatbiz.com/account` signs in like the apps and keeps a device token (platform `WEB`) in an `HttpOnly` cookie, `ingat_web`; page scripts never hold it. Requests must come from the page's own origin. A suspended account may sign in here, since paying is how it comes back.

| Method | Path | Notes |
|---|---|---|
| GET | `/download/android` | Public: the Android test build (APK) for people installing by hand; iPhone and iPad use TestFlight |
| GET | `/api/v1/web/visits` | Public: the website's visitor counter, `{ visitors, views, today }`. Every landing-page load counts a view, a browser counts as a visitor once (a year-long `ingat_seen` cookie), crawlers count nothing. The admin overview totals carry `siteVisitors` and `siteViewsToday` |
| GET | `/api/v1/web/config` | Public: `midtransClientKey`, `midtransProduction`, `appleServicesId`, `appleRedirectUri`, `googleClientId`. No secret |
| POST | `/api/v1/web/session/apple` | `{ identityToken, name? }` from Sign in with Apple JS (audience: the website's Services ID). Sets the cookie |
| POST | `/api/v1/web/session/google` | `{ idToken, nonce? }` from Google Identity Services. Sets the cookie |
| POST | `/api/v1/web/session/logout` | Clears the cookie |
| GET | `/api/v1/web/me` | `{ account, usage, discount, prices, orders }` |
| POST | `/api/v1/web/orders` | `{ kind: "PLAN_MONTH", plan }` or `{ kind: "BLOCK", blocks }` (1–100; needs a membership). Answers `{ order, snapToken }`; `snapToken` is null when a coupon covered the whole price and the order is already `PAID`. A money or percent coupon waiting on the account is taken off a month and used up by the order; it comes back if the order expires, fails or is cancelled |
| DELETE | `/api/v1/web/orders/:id` | Takes the order off the user's own list (`204`); the record stays for the books and the admin list |
| GET | `/api/v1/web/orders/:id/invoice.pdf` | A one-page PDF invoice with the IngatBiz mark, numbered `INV-YYYY-MM-XXXXXXXX`; English unless `?lang=ID`; `?inline=1` shows it in the browser instead of downloading. Any status; the status is printed on it |
| GET | `/api/v1/web/orders/:id` | Asks Midtrans first, then answers the order: `kind`, `plan`, `planLabel`, `blocks`, `reminders`, `listPriceIdr`, `discountIdr`, `amountIdr`, `status` (`PENDING`, `PAID`, `EXPIRED`, `FAILED`, `CANCELLED`, `REFUNDED`), `paymentType`, `paidAt`, `summary` |

Paying a month sets the membership and adds one calendar month to what is left (or starts today when the old membership ran out or differs), and reactivates a suspended account. Paying blocks adds `blocks × blockSize` reminders to the balance with a `PURCHASE` ledger line. Held deliveries are released either way.

### Midtrans

| Method | Path | Notes |
|---|---|---|
| POST | `/api/v1/billing/midtrans` | Public. Midtrans's payment notification (set the URL in the Midtrans dashboard). The `signature_key` (SHA-512 of order id, status code, gross amount and the server key) must match, else `401`. The order's standing is then read back from Midtrans and acted on; the notification body itself credits nothing. An amount that differs from the order's is left alone and logged |
| GET | `/api/v1/admin/orders` | Admin: payments received. `{ orders, count, totalIdr }`, paid orders newest first; `from`/`to` (ISO instants, on the paid day), `name` (account or user name), `status` (`PAID` default, or `PENDING`…, `ALL`), `limit` (500). Each order carries `accountId`, `accountName`, `ownerName` |

Settings: `MIDTRANS_ADAPTER` (`mock` or `midtrans`), `MIDTRANS_SERVER_KEY`, `MIDTRANS_CLIENT_KEY`, `MIDTRANS_PRODUCTION` (false: sandbox), `WEB_BASE_URL`, `APPLE_SERVICES_IDS`, `GOOGLE_CLIENT_IDS`.


### In-app purchases on iPhone and iPad (StoreKit)

The App Store sells the same things as the account page: a month of a membership (a non-renewing subscription) and one block of extra reminders (a consumable), one product of each per membership. Product ids are `<APPLE_IAP_PRODUCT_PREFIX>.month.<individual|team|business>` and `<prefix>.block.<plan>`, with the prefix `com.ingatbiz.ingat` unless set otherwise; the prices are set in App Store Connect, while the rupiah list price goes on the books from Pricing. From the app (device token):

| Method | Path | What it does |
|---|---|---|
| GET | `/api/v1/billing/apple/products` | The product ids to ask StoreKit for, each with `kind`, `plan`, `planLabel`, `reminders` (a month's included, or one block's size) and `listPriceIdr` |
| POST | `/api/v1/billing/apple/transactions` | Body `{ signedTransaction }`: the JWS StoreKit 2 gives for the purchase. The server checks the certificate chain ends in Apple Root CA - G3 and the signature verifies, that `bundleId` is one of `APPLE_BUNDLE_IDS` and the product is known, then credits the account exactly as a paid Midtrans order (`paymentType: apple`). The same `transactionId` sent again answers the same order with `alreadyCredited: true`. A Sandbox purchase (TestFlight, Xcode) is credited when `APPLE_IAP_ALLOW_SANDBOX` is on, recorded as `apple_sandbox` at Rp 0. `400` for another app's transaction, an unknown product, a refunded purchase or a signature that does not verify |

`APPLE_IAP_ADAPTER=mock` (tests) accepts a JWS with `alg: "mock"` and takes its payload as read.

## Help questions

| Method | Path | What it does |
|---|---|---|
| POST | `/api/v1/support` | App only. Body `{ text }`: a question to the operator, answered from the Admin screen |
| DELETE | `/api/v1/support/:id` | Takes one of the account's own questions back; `204`, or `404` for someone else's |
| GET | `/api/v1/support` | The account's questions with any replies, newest first |

## Recipients

| Method | Path | Purpose |
| --- | --- | --- |
| PUT | `/api/v1/recipients/me` | Who the account's user is: `{ name, waNumber, language? }`. Creates or updates the owner (active at once, may create reminders). `language` here is the account's language too: it picks the templates and samples the app shows. Other people keep their own `language` for the messages they get. Reminders with nobody chosen go to this person; messages name them as the sender |
| GET | `/api/v1/recipients` | Everyone, owner first |
| GET | `/api/v1/recipients/:id` | One person |
| POST | `/api/v1/recipients` | Add a person; sends them the opt-in message, `PENDING` until they reply YES. Whether they are asked first follows the account's `requireOptIn` (default off); `requireOptIn` in the body overrides it for this person |
| POST | `/api/v1/recipients/:id/activate` | Mark a `PENDING` person `ACTIVE` because they agreed in person; no message is sent. `409` if they replied STOP |
| POST | `/api/v1/recipients/:id/invite` | Send the opt-in again to a `PENDING` person; `409` within 10 minutes of the last one. Returns `{ sent }` |
| PATCH | `/api/v1/recipients/:id` | Change settings; a new number resets to `PENDING` and sends the opt-in again |
| DELETE | `/api/v1/recipients/:id` | Remove; cancels their unsent deliveries. Owner cannot be removed |

Fields: `name`, `aliases[]`, `waNumber`, `email` (optional, lower-cased; matches the person to a calendar attendee, see Self reminder), `avatar` (optional cartoon picture shown in the apps, `man-1`…`man-9` or `woman-1`…`woman-9`; `null` shows initials), `language` (`ID`/`EN`, the language this person's messages are sent in; omitted on create it is the account's language), `leadTimesMinutes[]` (accepted for older apps; no longer used, since each reminder carries its own)
(up to 5, e.g. `[0, 1440]`), `quietStartMinute`, `quietEndMinute` (minutes after
local midnight), `canCreate`, `escalateToOwner`.

## Groups

| Method | Path | Purpose |
| --- | --- | --- |
| GET, POST | `/api/v1/groups` | List, create (`name`, `memberIds[]`) |
| GET, PATCH, DELETE | `/api/v1/groups/:id` | Read, rename or replace members, remove |

## Reminders

| Method | Path | Purpose |
| --- | --- | --- |
| GET | `/api/v1/reminders?status=&from=&to=&limit=` | List, soonest first |
| GET | `/api/v1/reminders/:id` | One reminder with recipients and deliveries |
| POST | `/api/v1/reminders` | Create |
| PATCH | `/api/v1/reminders/:id` | Edit; moving `dueAt` or changing people re-plans deliveries |
| POST | `/api/v1/reminders/:id/recipients/:recipientId/done` | The owner marks one person done on their behalf: what they received becomes `DONE`, what was still to come for this occurrence is cancelled, and `recipients[].confirmedAt`/`confirmedVia: APP` is set. A Done on WhatsApp sets the same with `confirmedVia: WHATSAPP`. A one-off reminder closes once everyone has confirmed; a repeating one starts the next occurrence with everyone unconfirmed. `409` when the reminder is not open or the person is not on it |
| POST | `/api/v1/reminders/:id/recipients/:recipientId/nudge` | Sends the reminder once more, now, to a person who has not replied: a follow-up delivery goes out on the next sweep. `409` when nothing was sent to them yet, a message is already on its way, they confirmed, or they were nudged already |
| POST | `/api/v1/reminders/:id/skip` | A repeating reminder skips its current occurrence: nothing is sent for it and `dueAt` moves to the next occurrence (the series closes when its rule has ended). `409` unless open and repeating |
| POST | `/api/v1/reminders/:id/detach` | "Change only this occurrence": answers `{ occurrence, series }`. `occurrence` is a new one-off reminder for the current date with the same people, lead times and message, to edit freely; `series` is the repeating reminder moved on to its next occurrence. `409` unless open, repeating and still ahead |
| POST | `/api/v1/reminders/:id/close` | Mark done for everyone; cancels unsent deliveries |
| DELETE | `/api/v1/reminders/:id` | Remove |

Create fields: `id` (optional UUID chosen by the device; sending the same id again returns the
existing reminder instead of creating another), `title`, `notes`, `dueAt`, `timezone` (default Asia/Jakarta),
`repeatRule` (RRULE), `leadTimesMinutes[]` (when everyone on it is messaged: minutes before the due time, one message each, up to five; omitted means at the due time), `source` (`APP`/`SIRI`/`PENCIL`), `recipientIds[]`,
`groupIds[]`, `calendarKind` (`ICLOUD`/`OUTLOOK`). With no people named, the
reminder goes to the owner. Devices report the calendar event they wrote with
`PATCH {calendarEventExternalId}`.

Deliveries: one per person per lead time. `HELD` means the person has not opted
in yet; `SCHEDULED` means it will be sent at `fireAt`.

## Favourites

A reminder saved to make again in two taps: its people, lead times, message and usual time of day, under a name. Per account, from any device (device token).

| Method | Path | What it does |
|---|---|---|
| GET | `/api/v1/favourites` | All favourites, by name |
| POST | `/api/v1/favourites` | Create: `name` (1–60), `title`, `notes?`, `templateKey?`, `variables?`, `recipientIds[]`, `groupIds[]`, `leadTimesMinutes[]` (default `[0]`), `repeatRule?`, `calendarKind` (`ICLOUD`/`OUTLOOK`), `timeOfDayMinute?` (0–1439 in the account's time zone), and an optional client `id` so a retry is not a duplicate |
| PATCH | `/api/v1/favourites/:id` | Change any of the above |
| DELETE | `/api/v1/favourites/:id` | Remove it (reminders already made from it are untouched) |

The apps make the reminder themselves from a favourite (`POST /api/v1/reminders`), skipping people or groups that no longer exist.

## Sync

`GET /api/v1/sync` returns every live reminder, recipient, and group, plus
`serverTime`. Pass that back as `?since=<serverTime>` next time to receive only
what changed, including removed rows with `deletedAt` set.

## WhatsApp webhook

`/webhooks/whatsapp` is the address registered in Meta's dashboard (step 18).
No device token; instead `GET` checks `META_WEBHOOK_VERIFY_TOKEN` for Meta's
subscription handshake, and every `POST` must carry a valid
`X-Hub-Signature-256` made with `META_APP_SECRET`. Messages are stored once
(repeats from Meta are ignored), delivery receipts update sent messages, and
anything for another business number is dropped.

## Development only

Answer 404 in production and need a device token.

| Method | Path | Purpose |
| --- | --- | --- |
| POST | `/dev/whatsapp/inbound` | Pretend a WhatsApp message arrived: `{from, text}` or `{from, buttonPayload}` |
| GET | `/dev/whatsapp/outbox` | The last messages the mock adapter "sent" |

## Errors

`400` validation (with `issues[]`), `401` token, `404` not found, `409` conflict
(duplicate number or name, closed reminder, owner removal), `429` rate limit
(default 120 requests per minute per address), `503` from `/health` when the
database is down.

## Message counts

| Method | Path | What it does |
|---|---|---|
| GET | `/api/v1/stats/messages` | This month and last month: `templatesSent` (billed by Meta), `templatesFailed`, `repliesSent` (free), `byTemplate` |

## Templates

| Method | Path | What it does |
|---|---|---|
| GET | `/api/v1/templates` | Ingat's library plus this account's custom templates, with `key`, `language`, `title`, `body`, `fields` (placeholders the reminder must supply), `status` (`DRAFT`, `PENDING`, `APPROVED`, `REJECTED`) |
| POST | `/api/v1/templates` | A custom template: `title`, `language`, `body` with `{{placeholders}}` (must include `{{due}}`), `hasReplyButtons`, `samples`. Submitted to Meta; usable once `APPROVED`. Team: 3, Business: unlimited |
| DELETE | `/api/v1/templates/:id` | Retire a custom template |

A reminder names a template with `templateKey` and supplies its `fields` in `variables`; the server fills `requester` and `due`. Templated reminders are sent one per message and never merged.

## Reports

`GET /api/v1/reports/messages.csv?from&to`: every reminder message of the account in the window (default the last 30 days), one row per send: when, person, number, reminder, due, lead, state, delivered, read, reply, problem. `GET /api/v1/reports/messages.pdf?from&to` is the same on paper, landscape, one row per message (what the apps download).

| Method | Path | What it does |
|---|---|---|
| GET | `/api/v1/reports/monthly?month=YYYY-MM` | Messages sent / delivered / read / failed, reminders by template, deliveries due in the month by outcome (confirmed, snoozed, missed, undelivered, waiting), the same per person, and the plan usage. Defaults to this month |
| GET | `/api/v1/reports/monthly.csv?month=YYYY-MM` | The same as a CSV file |
| GET | `/api/v1/reports/monthly.pdf?month=YYYY-MM` | The same on paper: four tiles, summary, by person, by message, day by day (what the apps download) |

## Business API (API keys)

A Business account can make API keys from the app (`POST /api/v1/api-keys`, shown once as `ingat_live_…`; `GET` lists them, `DELETE /:id` revokes). A key is sent as `Authorization: Bearer ingat_live_…` and reaches everything above for its own account, except device-only routes (`/devices/me`) and key management itself. A revoked key, or a suspended account, answers `401`; a suspended account's devices get the same `401`.

| Method | Path | What it does |
|---|---|---|
| POST | `/api/v1/reminders` | As above; with `externalId` (your own reference) a repeat returns the existing reminder instead of making another. Reminders made with a key have `source: "API"` |
| GET | `/api/v1/reminders?externalId=…` | Find by your reference |
| POST | `/api/v1/reminders/bulk` | `{ rows: [...] }`, up to 500. Each row: `externalId`, `title`, `dueAt`, `to: { name, waNumber, language? }`, optional `templateKey` + `variables`, `notes`, `timezone` (IANA zone, else the row fails validation). The person is made if the number is new (asked on WhatsApp first if the account says so). Answers `{ created, existing, failed, rows: [{ externalId, status, reminderId?, recipientId?, error? }] }`; one bad row never stops the rest |

Example:

```bash
curl -X POST https://ingat.ingatbiz.com/api/v1/reminders/bulk \
  -H "Authorization: Bearer ingat_live_…" -H "Content-Type: application/json" \
  -d '{"rows":[{"externalId":"KPR-00123/2026-10","title":"Angsuran Oktober","dueAt":"2026-10-15T09:00:00+07:00",
        "to":{"name":"Budi Santoso","waNumber":"0812-3456-7890"},
        "templateKey":"payment_due","variables":{"name":"Budi Santoso","amount":"2.350.000","reference":"KPR-00123"}}]}'
```

## Webhooks (Business)

| Method | Path | What it does |
|---|---|---|
| POST | `/api/v1/webhooks` | `{ url, events? }`. The URL must be https and point to a public host: a private or local address, a host that resolves to one, or a URL with credentials in it is refused with `400`, and the check is repeated before every post. Redirects are not followed. Answers the endpoint with its `secret` once. Empty `events` means every event |
| GET | `/api/v1/webhooks` | Your endpoints (without secrets) |
| DELETE | `/api/v1/webhooks/:id` | Remove one |
| POST | `/api/v1/webhooks/:id/test` | Queue a `test` event |
| GET | `/api/v1/webhooks/:id/deliveries` | The last 50 posts with status, attempts and errors |
| GET | `/api/v1/reports/daily?date=YYYY-MM-DD` | One day's outcomes and who did not confirm (yesterday by default) |

Events: `reminder.sent`, `reminder.delivered`, `reminder.read`, `reminder.confirmed` (with `reply`), `reminder.snoozed` (with `until`), `reminder.missed`, `reminder.undelivered` (with `reason`), `person.opted_in`, `person.stopped`, `report.daily` (once a day from 07:00 in the account's time zone, for the day before), `test`.

Each post is JSON `{ id, event, occurredAt, reminder, person, delivery, ... }` with headers `X-Ingat-Event`, `X-Ingat-Delivery` and `X-Ingat-Signature: t=<unix seconds>,v1=<hex>`, where `v1` is HMAC-SHA256 with your secret over `"<t>.<raw body>"`. Answer 2xx within 10 seconds; anything else is retried after 1, 5, 15 and 60 minutes, then given up and shown in the deliveries log.

## Sandbox accounts

A sandbox account (ask for one) behaves like a Business account except that nothing it sends reaches WhatsApp. To test the whole flow:

| Method | Path | What it does |
|---|---|---|
| POST | `/api/v1/sandbox/replies` | `{ deliveryId, action }` with `done`, `snooze1h`, `snoozetmr`, `stop` or `yes`, or `{ deliveryId, text }`. Behaves exactly as if the person had replied on WhatsApp, but only within this sandbox account: a number that also belongs to a person in a real account is never affected |
| POST | `/api/v1/sandbox/receipts` | `{ deliveryId, status: "delivered" | "read" }` |

Delivery ids are in a reminder's `deliveries` (one per person per lead time). A sandbox account answers `403` on these routes once it is a real account.
