Print ZPL labels from Node.js
Build a ZPL string in Node.js and send it as raw base64. The agent does not render the label; the printer does.
For Node services that already generate ZPL
This page in another language: 中文
Overview
ZPL is text between ^XA and ^XZ. In Node it is a string you template with the order fields. Send it as content_type raw, not as a PDF you hope the driver will pass through.
Buffer.from(zpl, 'utf8') is correct for ZPL that is ASCII plus ^CI28 UTF-8 text. The agent strips a UTF-8 BOM and rejects PDF magic. A single-format label's copies can be folded into ^PQ.
This page is the English counterpart of the Chinese Node label page. The HTTP call is the same.
Create the job with POST /v1/print-jobs, an Authorization: Bearer header, printer_code, content_type pdf or raw, and exactly one of content or content_url. The free plan is 100 jobs a month on one computer.
Integration steps
- 01
Create an API key on the server
Use an API key (pb_live_…) in the process environment. Authorization is Bearer. Do not ship the key to browsers or mobile apps.
- 02
Install the agent beside the printer
Windows, macOS, or Linux. GET /v1/printers and keep the numeric code.
- 03
POST /v1/print-jobs
content_type is pdf or raw. Send exactly one of content (standard base64) or content_url.
- 04
Reuse the idempotency key on retry
A new key means a second physical print. HTTP 409 means the same key was reused with a different body.
- 05
Read the job before you tell the user
GET /v1/print-jobs/{id}. Paid plans can also receive print_job.completed and print_job.failed webhooks.
Node.js
// Node.js 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': `zpl:${orderId}`,
},
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
DPI is yours
203 dpi 4 by 6 inch labels are about 812 by 1218 dots. The API does not know the printhead.
Do not wrap ZPL in a PDF
If you only have a carrier PDF, send content_type pdf. Rebuilding it as ZPL is a different project.
Questions
Is there a Node ZPL library required?
No. Concatenate the string. A library is optional. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.
The label prints as one line of garbage.
The printer is not in ZPL mode, or you sent TSPL to a Zebra. Match the language.
Can I preview?
Labelary and similar tools render ZPL to an image. PrintBase does not render a preview.
Idempotency and copies?
The key identifies the job. copies is a separate field. A replay does not print another physical copy.
Free plan: 100 jobs a month on one computer, no card.