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.
|
||||
|
||||
+3
-3
@@ -51,9 +51,9 @@ argument, and lays it out for the printer in the config, as
|
||||
`/api/v1/preview` does. It prints nothing and fetches no images. On a
|
||||
terminal it shows bold, underlined and inverted text as such; warnings go
|
||||
to standard error. With `--module`, the input is that module's payload, as
|
||||
`/api/v1/print/:module` takes it, built at the time now. It reads the same
|
||||
config as the daemon, so `api.secret` and `printer.address` must be set even
|
||||
though neither is used.
|
||||
the `payload` field of a `/api/v1/print/:module` body holds it, built at
|
||||
the time now. It reads the same config as the daemon, so `api.secret` and
|
||||
`printer.address` must be set even though neither is used.
|
||||
|
||||
## config get
|
||||
|
||||
|
||||
+19
-15
@@ -338,25 +338,29 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
field of the wrong type would otherwise also be reported as missing.
|
||||
- A module checks its payload for everything the blocks would refuse, and
|
||||
words the problems in the payload's terms (`done[0]: index 5 is out of
|
||||
range`). A built job that still fails validation is a bug in the module:
|
||||
the client gets `422` `module_failed` with the problems, and it is
|
||||
logged and reported to Sentry once, without the problems, which can
|
||||
quote the payload.
|
||||
range`). The module routes name each by its path in the request body
|
||||
(`payload.done[0]`). A built job that still fails validation is a bug
|
||||
in the module: the client gets `422` `module_failed` with the problems,
|
||||
and it is logged and reported to Sentry once, without the problems,
|
||||
which can quote the payload.
|
||||
- Labels are in English, and the footer's time zone and date format come
|
||||
from the config (owner, 2026-11-29).
|
||||
- A module never reads the clock. It gets the time, zone and layout in an
|
||||
`Env`, from `format.timezone` and `format.time_layout`, so its output is
|
||||
reproducible in tests. The binary embeds the zone database, because
|
||||
Windows and slim containers have none.
|
||||
- Module routes take `copies` and the reserved `printer` (only `default`
|
||||
until a second printer is configured) in the query. Any other parameter
|
||||
is refused, for the same reason unknown config keys are: a typo must
|
||||
not be ignored.
|
||||
- A module route's body holds the payload under `payload`, with `copies`
|
||||
and the reserved `printer` (only `default` until a second printer is
|
||||
configured) beside it:
|
||||
`{"payload": {...}, "copies": 2, "printer": "default"}`. No name a
|
||||
module gives its payload's fields can collide with them. The body is
|
||||
decoded strictly, so any other field is refused, for the same reason
|
||||
unknown config keys are: a typo must not be ignored.
|
||||
- The registry lists modules sorted by name.
|
||||
- The module routes are entries in the route table like any other. The
|
||||
OpenAPI document describes their body as a JSON object whose fields the
|
||||
module defines, not as a strict schema: one route serves every module,
|
||||
and each module checks its own payload.
|
||||
OpenAPI document describes the payload as a JSON object whose fields
|
||||
the module defines, not as a strict schema: one route serves every
|
||||
module, and each module checks its own payload.
|
||||
- **Notifications print as one card.** The `notify` and `ntfy` modules turn
|
||||
their payloads into a `Notice` and lay it out with the same `Card`, which
|
||||
the ntfy subscriptions use too.
|
||||
@@ -502,10 +506,10 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
the request's JSON body, never in a query parameter. The path holds only
|
||||
a resource's ID, or a fixed word that names the route, as `last`,
|
||||
`failed` and `uncertain` do in `/jobs/.../reprint`. A `GET` takes no
|
||||
inputs beyond its path. Some of the API breaks the rule today, and a
|
||||
later change makes it follow:
|
||||
- the module routes' `copies` and `printer` query parameters, and the
|
||||
`invalid_query` error code that refuses them;
|
||||
inputs beyond its path. The module routes follow it: their body holds
|
||||
the module's payload, `copies` and `printer`, and a query string gets
|
||||
`400` `invalid_query`. Some of the plans break the rule today, and a
|
||||
later change makes them follow:
|
||||
- the `?printer=` that docs/plans/printers.md puts on `/print`,
|
||||
`/preview` and the module routes;
|
||||
- the filters and paging that docs/plans/job-store.md's phase 2 puts in
|
||||
|
||||
+29
-45
@@ -274,7 +274,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"details": {
|
||||
"description": "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). A job problem names the element by its path, e.g. elements[0].children[3] (qr); a payload problem names the field, e.g. done[0].",
|
||||
"description": "details lists every problem when a job fails validation (invalid_job), a module route's body or payload is invalid (invalid_payload) or a module builds an invalid receipt (module_failed). A job problem names the element by its path, e.g. elements[0].children[3] (qr); a module route's problem names the field by its path in the body, e.g. payload.done[0] or copies.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -471,8 +471,28 @@
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"ModulePayload": {
|
||||
"description": "ModulePayload is a module's payload: a JSON object whose fields the module defines, such as a note's title, text and items.",
|
||||
"ModuleRequest": {
|
||||
"additionalProperties": false,
|
||||
"description": "ModuleRequest is the body of the module routes: the module's payload, and the copies to print and the printer to print them on.",
|
||||
"properties": {
|
||||
"copies": {
|
||||
"description": "copies is how many times the receipt is printed, each with its own cut. Zero means one.",
|
||||
"maximum": 5,
|
||||
"minimum": 0,
|
||||
"type": "integer"
|
||||
},
|
||||
"payload": {
|
||||
"description": "payload is the module's payload: a JSON object whose fields the module defines, such as a note's title, text and items.",
|
||||
"type": "object"
|
||||
},
|
||||
"printer": {
|
||||
"description": "printer is reserved for a second printer: only default is accepted, and an empty name means it.",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"payload"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NtfyHealth": {
|
||||
@@ -1162,7 +1182,7 @@
|
||||
},
|
||||
"/api/v1/preview/{module}": {
|
||||
"post": {
|
||||
"description": "Builds the receipt as /api/v1/print/{module} does and answers as /api/v1/preview does: JSON with the lines' styles when the Accept header prefers application/json to text/plain, and plain text otherwise. It prints nothing and fetches no images.",
|
||||
"description": "Builds the receipt from the same body as /api/v1/print/{module} and answers as /api/v1/preview does: JSON with the lines' styles when the Accept header prefers application/json to text/plain, and plain text otherwise. It prints nothing and fetches no images.",
|
||||
"operationId": "previewModule",
|
||||
"parameters": [
|
||||
{
|
||||
@@ -1173,31 +1193,13 @@
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "How many copies to print, each cut separately: a whole number, 1-5. Default 1.",
|
||||
"in": "query",
|
||||
"name": "copies",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Reserved for a second printer: only default is accepted. Any other query parameter is refused.",
|
||||
"in": "query",
|
||||
"name": "printer",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ModulePayload"
|
||||
"$ref": "#/components/schemas/ModuleRequest"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1230,7 +1232,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "Bad Request. invalid_payload: invalid payload; invalid_query: invalid query parameter; unknown_printer: unknown printer.",
|
||||
"description": "Bad Request. invalid_payload: invalid payload; invalid_query: query parameters are not accepted; unknown_printer: unknown printer.",
|
||||
"x-uberbringer-codes": [
|
||||
"invalid_payload",
|
||||
"invalid_query",
|
||||
@@ -1523,7 +1525,7 @@
|
||||
},
|
||||
"/api/v1/print/{module}": {
|
||||
"post": {
|
||||
"description": "The module named in the path builds a receipt from the body, its own payload. note and notify decode it strictly: an unknown field or one of the wrong type is refused, with every problem listed; ntfy ignores the fields it does not know. The receipt is then validated and queued as on /api/v1/print. A module with nothing to print answers 204. A token limited to modules (uberbringer token --modules) may use only the modules it names.",
|
||||
"description": "The module named in the path builds a receipt from the body's payload, a JSON object whose fields the module defines; copies and printer sit beside it. The body is decoded strictly, and so are the payloads of note and notify: an unknown field or one of the wrong type is refused, with every problem listed. ntfy ignores the payload fields it does not know. The receipt is then validated and queued as on /api/v1/print. A module with nothing to print answers 204. A token limited to modules (uberbringer token --modules) may use only the modules it names.",
|
||||
"operationId": "printModule",
|
||||
"parameters": [
|
||||
{
|
||||
@@ -1534,31 +1536,13 @@
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "How many copies to print, each cut separately: a whole number, 1-5. Default 1.",
|
||||
"in": "query",
|
||||
"name": "copies",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Reserved for a second printer: only default is accepted. Any other query parameter is refused.",
|
||||
"in": "query",
|
||||
"name": "printer",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ModulePayload"
|
||||
"$ref": "#/components/schemas/ModuleRequest"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1594,7 +1578,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "Bad Request. invalid_payload: invalid payload; invalid_query: invalid query parameter; unknown_printer: unknown printer.",
|
||||
"description": "Bad Request. invalid_payload: invalid payload; invalid_query: query parameters are not accepted; unknown_printer: unknown printer.",
|
||||
"x-uberbringer-codes": [
|
||||
"invalid_payload",
|
||||
"invalid_query",
|
||||
|
||||
Reference in new issue
Block a user