How to auto-print labels from Retool
Add a Retool REST query that posts a label to the print API. Keep the API key in a Retool resource, not in the app export.
For Internal Retool apps used by a warehouse or a lab bench
Overview
Retool apps are internal tools with buttons. A button can run a REST query. PrintBase does not have a Retool integration to install. You create a resource with the base URL https://api.printbase.cloud and an Authorization header.
The query POSTs /v1/print-jobs. printer_code can be a select component bound to a query on GET /v1/printers. The label payload is ZPL or PDF you assembled from the table row. Do not ship the API key inside a publicly exported app.
Use the row id as Idempotency-Key so a double click does not print two labels. Provide a separate reprint button that appends a timestamp only when the operator means it.
Integration steps
- 01
Create a REST resource
Base URL https://api.printbase.cloud. Header Authorization Bearer from a Retool secret.
- 02
GET /v1/printers for the dropdown
Display name, submit code as printer_code. Use POST /v1/print-jobs with Authorization: Bearer and the printer_code from GET /v1/printers.
- 03
Build the label from the selected row
ZPL for Zebras, PDF for driver printers. Use POST /v1/print-jobs with Authorization: Bearer and the printer_code from GET /v1/printers.
- 04
POST /v1/print-jobs
Bind printer_code, content, content_type, and the idempotency header.
- 05
Show job.status in the app
A follow-up GET on the returned id. Do not only toast 'query succeeded'.
Node.js
// Retool REST query body for a ZPL label
const res = await fetch('https://api.printbase.cloud/v1/print-jobs', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PRINTBASE_API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': `retool:${row.id}`,
},
body: JSON.stringify({
printer_code: Number(process.env.PRINTER_CODE),
content_type: 'raw',
content: Buffer.from(zpl, 'utf8').toString('base64'),
copies: 1,
}),
});
if (!res.ok) throw new Error(`PrintBase ${res.status}: ${await res.text()}`);
const job = await res.json();
// { id: "job_abc", status: "queued" }
Details for this setup
Raw bytes for a Retool ZPL label
Use content_type raw. The agent refuses a PDF, PNG, or JPEG disguised as raw and returns INVALID_CONTENT. Windows sends the bytes to the spooler from memory. macOS and Linux call lp -o raw. For a single ^XA…^XZ label with copies greater than 1 and no existing ^PQ, ^SN, or ^SF, the agent inserts ^PQ so the printer repeats the label.
Resource permissions
Limit who can edit the resource. Viewers of the app should run the query, not read the Bearer token.
Questions
Is there a Retool plugin?
No. It is a REST resource. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.
Can I list printers in the app?
Yes. GET /v1/printers with the printers:read scope. The create call needs print:create.
The query returns 401.
The Bearer token is missing or not an API key. User JWTs and API keys both use Authorization Bearer, but a server integration should use an API key (pb_live_…).
Operators need two printers.
Two queries or a select bound to printer_code. The API does not fan out to every printer unless you send multiple jobs.
Free plan: 100 jobs a month on one computer, no card.