Take a module route's copies and printer in its JSON body
API inputs go in the JSON body, never in query parameters (owner,
2026-12-01; design.md, "Inputs go in the JSON body"). The module routes
took copies and printer in the query, beside a body that was the
module's payload alone.
The body of POST /api/v1/print/{module} and /api/v1/preview/{module}
now holds the payload under payload, with copies and printer beside it:
{"payload": {...}, "copies": 2, "printer": "default"}. A module may name
its payload's fields as it likes, since none can collide with copies or
printer; that matters for ntfy's messages and for any module that takes
another system's JSON. The body is decoded strictly, and its problems
are answered at once as invalid_payload, each named by its path in the
body: copies, or, once the body is right, payload.done[0] for one the
module finds. A field named body is quoted, "body", so it is never
taken for a problem with the whole body. copies takes 0-5, as a job's
does, 0 meaning one. A query string on these routes gets 400
invalid_query, now worded "query parameters are not accepted".
The ntfy client recipes in docs/api.md wrap $NTFY_RAW in the body. The
Windows command was run here through cmd.exe and PowerShell, and the
printf of the Linux one in sh, each with a message holding quotes, & and
%; neither ran under an ntfy client. No tag carries the module query, so
the 0.2.0 entries in the CHANGELOG change in place (owner, 2026-12-01).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cbac0b5f03
commit
9e829bfce7
16 files changed
+336
-217
No files matched your search
+39
-27
@@ -290,19 +290,19 @@ Errors are JSON:
|
||||
- `error` is for people and may change. It never repeats the HTTP
|
||||
framework's own text; for example, an unknown route answers `not found`.
|
||||
- `details` lists every problem when a job fails validation (`invalid_job`),
|
||||
a module payload is invalid (`invalid_payload`) or a module builds an
|
||||
invalid receipt (`module_failed`), and the raw elements a token may not
|
||||
print (`token_scope`). Each job problem names the element by its path,
|
||||
e.g.
|
||||
a module route's body or payload is invalid (`invalid_payload`) or a
|
||||
module builds an invalid receipt (`module_failed`), and the raw elements
|
||||
a token may not print (`token_scope`). Each job problem names the element
|
||||
by its path, e.g.
|
||||
`elements[0].children[3] (qr): not allowed inside a box; place it after the box`,
|
||||
and each payload problem names the field, e.g.
|
||||
`done[0]: index 5 is out of range`.
|
||||
and each problem with a module route's body names the field by its path
|
||||
in the body, e.g. `payload.done[0]: index 5 is out of range`.
|
||||
|
||||
| Status | `code` | Meaning |
|
||||
|--------|--------|---------|
|
||||
| 400 | `invalid_job` | Malformed JSON, an unknown field, trailing data after the job, or invalid elements. When elements are invalid, `details` lists every problem. A `{"data": [...]}` body gets a message pointing to the [element format](#elements) |
|
||||
| 400 | `invalid_payload` | A [module](#modules) payload that is not a JSON object, has an unknown field or a field of the wrong type, or is invalid, e.g. `invalid payload for module "note"`. `details` lists every problem |
|
||||
| 400 | `invalid_query` | On a module route: `copies` outside 1–5, a parameter given twice, or a parameter other than `copies` and `printer` |
|
||||
| 400 | `invalid_payload` | A [module](#modules) route's body or payload that is not a JSON object, has an unknown field or a field of the wrong type, or is invalid, e.g. `invalid payload for module "note"`, or a body whose `copies` is outside 1–5. `details` lists every problem |
|
||||
| 400 | `invalid_query` | On a module route: the request has a query string. Every input goes in the JSON body |
|
||||
| 400 | `unknown_printer` | On a module route: `printer` names a printer other than `default` |
|
||||
| 400 | `bad_request` | A malformed HTTP request, refused by the server itself |
|
||||
| 401 | `unauthorized` | `missing bearer token`, or `invalid or expired token`. Sent with `WWW-Authenticate` |
|
||||
@@ -626,31 +626,43 @@ elements. `GET /api/v1/modules` lists them:
|
||||
{"name": "ntfy", "description": "One ntfy message object, e.g. the CLI's $NTFY_RAW"}]
|
||||
```
|
||||
|
||||
The body of a module route holds the payload under `payload`, with the
|
||||
copies to print and the printer to print them on beside it:
|
||||
|
||||
```sh
|
||||
curl -X POST https://printer.example.com/api/v1/print/note \
|
||||
-H @"$HOME/.uberbringer-auth" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"title": "Shopping", "text": "Milk, eggs and the good bread from the bakery on Elm St.",
|
||||
"items": ["Milk", "Eggs", "Bread"], "done": [2]}'
|
||||
-d '{"payload": {"title": "Shopping", "text": "Milk, eggs and the good bread from the bakery on Elm St.",
|
||||
"items": ["Milk", "Eggs", "Bread"], "done": [2]}}'
|
||||
```
|
||||
|
||||
| Field | Default | Values |
|
||||
|-----------|-----------|--------|
|
||||
| `payload` | | Required. The module's payload: a JSON object whose fields the module defines, as the sections below describe |
|
||||
| `copies` | `1` | 1–5, each copy cut separately; `0` means one |
|
||||
| `printer` | `default` | Reserved for a second printer: only `default` is accepted |
|
||||
|
||||
`POST /api/v1/print/:module` answers as `/api/v1/print` does: `202` with the
|
||||
job and a `Location` header, or `503` when the queue is full or closing.
|
||||
`POST /api/v1/preview/:module` takes the same payload and answers as
|
||||
`POST /api/v1/preview/:module` takes the same body and answers as
|
||||
[`/api/v1/preview`](#preview-a-receipt) does. On both routes:
|
||||
|
||||
- `204` with no body means the module had nothing to print.
|
||||
- `400` `invalid_payload` lists every problem with the payload in `details`.
|
||||
`note` and `notify` decode their payloads strictly: an unknown field, or a
|
||||
field name in another case, is a problem. `ntfy` takes ntfy's messages as
|
||||
they are and ignores the fields it does not know.
|
||||
- `400` `invalid_payload` lists every problem with the body in `details`,
|
||||
each named by its path in the body, e.g. `copies: must be 1-5`. Once the
|
||||
body is right, it lists every problem with the payload in the same way,
|
||||
e.g. `payload.done[0]: index 5 is out of range`. The body, and the
|
||||
payloads of `note` and `notify`, are decoded strictly: an unknown
|
||||
field, or a field name in another case, is a problem. `ntfy` takes
|
||||
ntfy's messages as they are and ignores the fields it does not know.
|
||||
- `400` `unknown_printer` means `printer` names a printer other than
|
||||
`default`.
|
||||
- `400` `invalid_query` means the request has a query string: every input
|
||||
goes in the body.
|
||||
- `404` `module_not_found` names an unknown module.
|
||||
- `422` `module_failed` means the module built a receipt that fails
|
||||
validation. That is a bug in the module, and it is logged.
|
||||
- The query may set `copies` (1–5, each copy cut separately) and `printer`,
|
||||
which is reserved: only `default` is accepted. Any other query parameter,
|
||||
or one given twice, is `400` `invalid_query`, and another printer name is
|
||||
`400` `unknown_printer`.
|
||||
|
||||
`uberbringer preview --module note payload.json` shows the receipt without
|
||||
the daemon.
|
||||
@@ -698,9 +710,9 @@ phone shortcuts. The smallest payload is `{"message": "Back at 3"}`:
|
||||
curl -X POST https://printer.example.com/api/v1/print/notify \
|
||||
-H @"$HOME/.uberbringer-auth" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"title": "Disk almost full", "message": "/var is at 94% on nas01", "priority": "high",
|
||||
"tags": ["warning", "nas01"], "topic": "alerts", "click": "https://grafana.lan/d/disk",
|
||||
"actions": [{"label": "Open dashboard", "url": "https://grafana.lan/d/disk"}]}'
|
||||
-d '{"payload": {"title": "Disk almost full", "message": "/var is at 94% on nas01", "priority": "high",
|
||||
"tags": ["warning", "nas01"], "topic": "alerts", "click": "https://grafana.lan/d/disk",
|
||||
"actions": [{"label": "Open dashboard", "url": "https://grafana.lan/d/disk"}]}}'
|
||||
```
|
||||
|
||||
```text
|
||||
@@ -734,14 +746,14 @@ curl -X POST https://printer.example.com/api/v1/print/notify \
|
||||
| `time` | now | When it happened: Unix seconds, or RFC 3339 such as `2026-11-29T21:04:05Z` |
|
||||
|
||||
A payload over a limit is `400` `invalid_payload`, e.g.
|
||||
`title: 300 characters, limit is 250`.
|
||||
`payload.title: 300 characters, limit is 250`.
|
||||
|
||||
### `ntfy`
|
||||
|
||||
One message from [ntfy](https://ntfy.sh)'s subscribe API, exactly as ntfy
|
||||
sends it, printed as a [notification card](#notification-cards). The ntfy
|
||||
command line client passes such a message to a command in `$NTFY_RAW`, so
|
||||
it can be posted as it is:
|
||||
it can be posted as the payload, unchanged:
|
||||
|
||||
```json
|
||||
{"id": "sPs71M8A2Tq9", "time": 1795986245, "event": "message", "topic": "alerts",
|
||||
@@ -776,7 +788,7 @@ attachment expires:
|
||||
```
|
||||
|
||||
- Fields the module does not know are ignored, so messages from newer ntfy
|
||||
versions still print. A body that is not one JSON object, or a known
|
||||
versions still print. A payload that is not one JSON object, or a known
|
||||
field of the wrong type, is `400` `invalid_payload`.
|
||||
- Events other than `message` (`open`, `keepalive`, `poll_request`,
|
||||
`message_delete`, `message_clear`) and messages with a binary body
|
||||
@@ -830,7 +842,7 @@ default-token: tk_...
|
||||
subscribe:
|
||||
- topic: alerts
|
||||
command: |
|
||||
printf '%s' "$NTFY_RAW" | curl -fsS -X POST \
|
||||
printf '{"payload":%s}' "$NTFY_RAW" | curl -fsS -X POST \
|
||||
-H @"$HOME/.config/ntfy/uberbringer-auth" -H "Content-Type: application/json" \
|
||||
--data-binary @- https://printer.example.com/api/v1/print/ntfy
|
||||
if:
|
||||
@@ -857,7 +869,7 @@ On Windows, `cmd.exe` breaks `%NTFY_RAW%`, so the command runs PowerShell,
|
||||
with the token in the client's environment as `UBERBRINGER_TOKEN`:
|
||||
|
||||
```yaml
|
||||
command: powershell -NoProfile -Command "Invoke-RestMethod -Method Post -Uri https://printer.example.com/api/v1/print/ntfy -Headers @{Authorization=('Bearer ' + $env:UBERBRINGER_TOKEN)} -ContentType 'application/json' -Body ([Text.Encoding]::UTF8.GetBytes($env:NTFY_RAW))"
|
||||
command: powershell -NoProfile -Command "Invoke-RestMethod -Method Post -Uri https://printer.example.com/api/v1/print/ntfy -Headers @{Authorization=('Bearer ' + $env:UBERBRINGER_TOKEN)} -ContentType 'application/json' -Body ([Text.Encoding]::UTF8.GetBytes('{\"payload\":' + $env:NTFY_RAW + '}'))"
|
||||
```
|
||||
|
||||
`if:` picks the priorities that print; leave it out to print them all.
|
||||
|
||||
Reference in new issue
Block a user