# Deckboard API

Deckboard (https://deckboard.party) shows a photoreal split-flap board hung in a room, in the browser. This API lets another service run a board: set its notices, give each its own time or pin one in place, attach a link to each (shown as a QR code in a small frame beside the board, behind a roller shutter, and as a flat code in the corner of every screen), set a "buy screentime" link (a second code), push notices that take the board in turn (for example a paid question on a live stream), and read or clear that queue.

- Human-readable reference: https://deckboard.party/docs/api/
- OpenAPI 3.1: https://deckboard.party/docs/api/openapi.json
- Base URL: `https://deckboard.party/api`
- Bodies are JSON (`Content-Type: application/json`). Times are Unix milliseconds unless a field says seconds.

## Authentication

The account owner makes an API key at https://deckboard.party/account and gives it to your service. Send it on every request:

```
Authorization: Bearer dk_<40 hex characters>
```

A key acts for its account on that account's boards (up to 3 boards per account). A key cannot make or revoke keys, change the username or close the account: those need the owner signed in in a browser. Keep the key on your server; it is a password. A revoked key fails at once with `401 bad_key`.

## How a board decides what to show

1. If a **pushed notice** is due (`startsAt <= now < endsAt`), the board shows it.
2. Otherwise, if a notice is **pinned** (`pinned` is its index), the board holds that one. Pushed notices still take over for their time, then the board goes back to the pin.
3. Otherwise it shows its own **notices** in turn. Each holds for its own `seconds[i]`, or `holdSeconds` when that is `null`. The turn is timed on the server clock so every screen flips together: one full turn (the cycle) is the sum of the notices' times, and the notice showing at time `t` (Unix ms) is the one whose slot `t mod cycle` falls in, counting from notice 0.

Each notice, pushed or not, may have a **link**. The frame beside the board shows the link as a QR code. When the notice changes, the frame's roller shutter comes down, the code changes and it rolls back up. A notice without a link keeps the shutter down. Links longer than 48 characters are encoded as a short `https://deckboard.party/go/<code>` redirect (the `qr` field), so the code stays small enough to scan from a video stream.

Screens (the public address and private screen links) also draw flat QR codes in the bottom-left corner, over the picture: **Scan for details** for the notice showing now (pushed or not; hidden when it has no link) and **Buy screentime** for the board's `buyLink` (hidden when that is `null`). They stay up when the pointer idles, and are left out with `?clean`.

## Board object

| field | type | notes |
|---|---|---|
| `id` | string | 24 hex characters |
| `name` | string | 1-40 characters |
| `owner` | string | the owner's username |
| `slug` | string | public address `https://deckboard.party/{owner}/{slug}`; follows the name until set explicitly |
| `public` | boolean | default `true`; when `false` only the owner and private screen links can see it |
| `size` | `note` \| `medium` \| `large` | 3 rows x 15, 6 x 22, 8 x 32 characters |
| `scene` | string | the room, one of `GET /catalog` `scenes[].id` |
| `sound` | `station` \| `card` \| `enamel` \| `glass` | |
| `messages` | string[][] | the board's own notices (1-12), each a list of rows padded to the board |
| `links` | (string\|null)[] | parallel to `messages` |
| `qr` | (string\|null)[] | read only: what each QR code encodes |
| `message` | string[] | read only: the first notice |
| `holdSeconds` | integer | 3-3600, default 20: how long each of the board's own notices holds, unless it has its own time |
| `seconds` | (integer\|null)[] | parallel to `messages`: each notice's own hold, 3-3600 (numbers outside are clamped); `null` = `holdSeconds` |
| `pinned` | integer\|null | index into `messages` of the notice fixed on the board (no turning; pushes still take over); `null` = rotate |
| `buyLink` | string\|null | the owner's "buy screentime" URL, shown as a second QR code on screens |
| `buyQr` | string\|null | read only: what that code encodes (the link, or a short `/go/` address, as with `qr`) |
| `pushSeconds` | integer | 3-3600, default 30: default length of a pushed notice |
| `queue` | Push[] | read only: pushed notices showing or waiting, in order |
| `viewpoint` | object\|null | `{pos:[x,y,z], target:[x,y,z], fov}`: where the camera stands (set by the owner) |
| `updatedAt` | integer | Unix seconds |
| `now` | integer | server time when sent, Unix ms |
| `displayLink` | object\|null | owner view only: `{prefix}` of the private screen link |

## Push object

```json
{"id": "p_04270540d1bfc3d39135", "message": ["SAM ASKS: WHAT", "IS THE BEST", "BOARD?"],
 "link": "https://sam.example/show", "qr": "https://sam.example/show", "ref": "pay_8812",
 "startsAt": 1794450001500, "endsAt": 1794450046500}
```

## Endpoints

### Catalog (no key)

`GET /catalog`: `{sizes, scenes, sounds, drum, maxBoards}`. `drum` is every character the cards carry.

### Account

- `GET /me`: the account behind the key: `{user: {id, email, username, emailVerified, created}}`.
- `PATCH /me {"username": "..."}`: session only. 3-30 of a-z, 0-9 and single hyphens; unique; some words are reserved. The account's board addresses change with it.
- `GET /keys`, `POST /keys {"name": "..."}` (returns `{key, token}`; the token is shown once), `DELETE /keys/{keyId}`: session only.

### Boards

- `GET /boards`: `{boards: [Board], max: 3}`.
- `POST /boards`: make a board (fields as in PATCH; at most 3 per account, else `409 board_limit`). Returns `201 {board}`.
- `GET /boards/{id}`: `{board}`.
- `PATCH /boards/{id}`: change any of `name`, `slug`, `public`, `size`, `scene`, `sound`, the notices, `holdSeconds`, `pinned`, `buyLink`, `pushSeconds`, `viewpoint`. Returns `{board}`.
- `DELETE /boards/{id}`: take the board down; its queue goes with it.

Set notices in any of these shapes:

```json
{"notices": [
  {"text": "Ask me anything, live Fridays", "link": "https://pod.example/ask", "seconds": 40},
  {"message": ["", "NEXT SHOW", "FRIDAY 8PM"], "link": null, "seconds": null}
], "holdSeconds": 15, "pinned": null, "buyLink": "https://pod.example/buy-screentime"}
```

```json
{"messages": [["HELLO"], ["WORLD"]], "links": ["https://a.example", null], "seconds": [10, null]}
```

```json
{"text": "Back in five", "link": null}
```

The last shape replaces the list with one notice and keeps the pace. `text` wraps at word boundaries, keeps line breaks, and splits a word longer than a row. If it doesn't fit, you get `400 too_long` and nothing changes. `message` is rows exactly as you lay them out (upper-cased, padded; a row longer than the board is refused).

Times and the pin:

- A notice's `seconds` may be left out or `null` for the board's `holdSeconds`. The single-notice shape takes a number `seconds` too.
- `links` and `seconds` lists may also be sent on their own, for the current notices. A shorter list leaves the rest `null`; a longer one is refused. Sending `messages` alone keeps each position's link and time.
- `{"pinned": 0}` fixes notice 0 on the board; `{"pinned": null}` goes back to turning. If a new list is too short for the pin, the pin is dropped.
- `{"buyLink": "https://..."}` sets the buy-screentime code (same rules as notice links); `{"buyLink": null}` removes it.

### Pushed notices (the queue)

`POST /boards/{id}/push`

| field | | |
|---|---|---|
| `text` or `message` | required | the notice |
| `link` | optional | URL for the QR code |
| `seconds` | optional | 3-3600; default the board's `pushSeconds` |
| `ref` | optional | up to 200 characters: your own id (a payment, a message) |

The notice joins the end of the queue. It starts when the one before it ends, or about 1.5 s from now if nothing is waiting. Response `201`: `{push, position, now}` (`position` 0 = next or showing). At most 100 may wait; 120 pushes a minute per board.

- `GET /boards/{id}/queue`: `{queue: [Push], now}`, the one showing first.
- `DELETE /boards/{id}/queue/{pushId}`: remove one. If it is showing, it ends now; the rest move up in order.
- `DELETE /boards/{id}/queue`: clear all.

### Screens

- Public address: `https://deckboard.party/{owner}/{slug}`. Full screen, from the owner's saved camera place; visitors may drag to look about (never saved). Use it as a stream's browser source.
- `GET /u/{owner}/{slug}` (no key): `{board}`, or `404` if private.
- Private screen link: `POST /boards/{id}/display-link` returns `{token, url}` (shown once; the old link stops working). `DELETE /boards/{id}/display-link` cuts it. `GET /display/{token}` (no key) returns the board.
- Live updates (WebSocket): `wss://deckboard.party/api/u/{owner}/{slug}/live` (public boards) and `wss://deckboard.party/api/display/{token}/live`. Messages: `{"type":"board","board":Board}`, `{"type":"deleted"}`, `{"type":"revoked"}`. Send `ping` every 30 s; the answer is `pong`.

## Characters

A-Z (lower case is upper-cased), 0-9, and `. - : ! ? ' / & , $ ; " # % @ * ( ) [ ] { } < > + = _ ^ ~ \ | `` ` ``, plus space. Anything else is refused with `400 bad_message` naming the character; nothing is silently dropped.

## Errors and limits

Errors: `{"error": {"code": "...", "message": "..."}}` with an HTTP status.

| code | status | when |
|---|---|---|
| `bad_key` | 401 | missing, malformed or revoked key |
| `unauthorized` | 401 | no key and no session |
| `session_required` | 403 | keys, username and closing the account need a signed-in session |
| `not_found` | 404 | no such board on this account / no such pushed notice / private board |
| `bad_message`, `too_long`, `bad_messages`, `bad_notices` | 400 | characters, row length, fit, list size |
| `bad_link` | 400 | not an http(s) URL, or over 2000 characters |
| `bad_seconds`, `bad_hold` | 400 | not a number, outside 3-3600 (pushes and `holdSeconds`), or more `seconds` than notices |
| `bad_pinned` | 400 | `pinned` is neither `null` nor the index of a notice |
| `bad_slug`, `bad_username` | 400 | wrong form or reserved |
| `queue_full` | 409 | 100 notices already waiting |
| `slug_taken`, `username_taken`, `board_limit` | 409 | |
| `rate_limited` | 429 | 600 requests a minute per key; 120 pushes a minute per board |

## Example: paid questions on a stream

Your service runs the page where viewers ask, takes the payment and checks the content. Deckboard shows what you send.

```sh
curl https://deckboard.party/api/boards/$BOARD/push \
  -H "Authorization: Bearer $DECKBOARD_KEY" -H "Content-Type: application/json" \
  -d '{"text": "SAM ASKS: WHAT IS THE BEST BOARD?", "link": "https://sam.example/show", "seconds": 45, "ref": "pay_8812"}'
```

Tell the viewer when they'll be on from `push.startsAt`. If the payment is refunded, `DELETE /api/boards/$BOARD/queue/{push.id}`.
