Printing from an application
When printing is on for your server (see Printing), an application prints with one HTTP request to the server’s print service. This is the full description for developers.
The two variables
Section titled “The two variables”The platform gives a stack two values, the same way as global variables:
| Variable | Content |
|---|---|
HDDEPLOY_PRINT_URL |
The address of the print service, http://hddeploy-printing:8631 |
HDDEPLOY_PRINT_TOKEN |
This server’s print token (hidden: the portal, the API and assistants never show it) |
A container gets them only when the compose file passes them to the service that prints:
services: app: environment: HDDEPLOY_PRINT_URL: ${HDDEPLOY_PRINT_URL} HDDEPLOY_PRINT_TOKEN: ${HDDEPLOY_PRINT_TOKEN} networks: [hddeploy]The service must be on the hddeploy network (every service behind Traefik already is). After a Deploy the container has the values. When HD Services replaces the print token, the Printers page names the stacks that need a new deploy.
Always print from the server (the application’s backend), never from the browser: the print token does not belong in a web page.
Printing a PDF
Section titled “Printing a PDF”POST {HDDEPLOY_PRINT_URL}/v1/print/{print target}?copies=2Authorization: Bearer {HDDEPLOY_PRINT_TOKEN}Content-Type: application/pdfIdempotency-Key: workorder-4711-v1
<the PDF>{print target}is the code of a print target, such asoffice-1-blank.GET /v1/targetslists them.copies(optional) is the number of copies or labels; without it the print target’s default applies. More than the print target’s maximum is refused.Idempotency-Key(optional, up to 128 characters): the same key within 24 hours returns the first job instead of printing again. Use it for buttons a user may press twice.- The body is a PDF of at most 20 MB.
The answer is 202 Accepted with the job:
{ "id": "pj_3f9c2a71b0d4e8a1", "target": "office-1-blank", "copies": 2, "bytes": 48213, "state": "queued", "createdAt": "2026-11-18T14:02:11Z", "updatedAt": "2026-11-18T14:02:11Z" }Following the state
Section titled “Following the state”GET {HDDEPLOY_PRINT_URL}/v1/jobs/{id} (with the same token) returns the job with state:
| state | Meaning |
|---|---|
queued |
Waiting in the print queue. |
printing |
Being sent to the printer. |
done |
Finished. For a printer over RAW (port 9100, such as a DYMO print server) this means: the printer accepted the data; the server cannot see an empty paper tray there. Over IPP and IPPS the printer itself reports completion. |
failed |
Failed; reason says why. A job the printer has not taken after 10 minutes is cancelled. |
Jobs can be read for 24 hours.
Labels
Section titled “Labels”A label is a PDF of exactly the label size, one label per page. GET /v1/targets gives widthPt and heightPt for a label target (in points, 1 pt = 1/72 inch). For the DYMO label 11354 (57 x 32 mm) that is 162 x 90 pt, landscape. Keep about 1.5 mm free all round. The layout (text, barcode, logo) is the application’s; several identical labels: copies.
The list of print targets
Section titled “The list of print targets”GET {HDDEPLOY_PRINT_URL}/v1/targets:
[ { "id": "dymo-label", "label": "DYMO label", "kind": "label", "defaultCopies": 1, "maxCopies": 50, "state": "ready", "widthPt": 162, "heightPt": 90 }, { "id": "office-1-blank", "label": "Office 1 blank", "kind": "office", "defaultCopies": 1, "maxCopies": 10, "state": "ready" } ]state is the printer’s state: ready, offline, setup or refused. A “Print” button can stay disabled while the printer is not ready.
Errors
Section titled “Errors”Errors come as application/problem+json with a readable detail:
| Code | When |
|---|---|
401 |
No or a wrong print token. |
404 |
Unknown print target or unknown job. |
413 |
The PDF is larger than 20 MB. |
422 |
The body is not a PDF, or copies is outside 1 to the maximum. |
503 |
The printer is not reachable or blocked. The job is not kept: tell the user at once instead of printing later. |
Example (Node.js)
Section titled “Example (Node.js)”const res = await fetch(`${process.env.HDDEPLOY_PRINT_URL}/v1/print/office-1-blank?copies=1`, { method: "POST", headers: { Authorization: `Bearer ${process.env.HDDEPLOY_PRINT_TOKEN}`, "Content-Type": "application/pdf", "Idempotency-Key": `workorder-${order.id}-${order.version}`, }, body: pdfBuffer,});if (!res.ok) { const problem = await res.json(); throw new Error(problem.detail); // e.g. "the printer is not reachable: ..."}const job = await res.json(); // { id, state: "queued", ... }Testing a print target
Section titled “Testing a print target”Test a print target on the Printers page (Test page), with the API (POST /api/v1/printing/targets/{id}/test), the command-line tool (hddeploy printer test {id}) or an assistant (print_test_page). It prints a page with a frame; the frame must come out complete.