JavaScript Quickstart
The one-line version, for reference:
curl -X POST "https://api.labelzoom.com/api/v2/convert/zpl/to/pdf" -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: text/plain" -d '^XA^FO50,50^ADN,36,20^FDLabelZoom^FS^XZ' --output label.pdfThe same conversion with fetch (Node.js 18+, Bun, Deno, or serverless runtimes):
import { writeFile } from "node:fs/promises";
const zpl = "^XA^FO50,50^ADN,36,20^FDLabelZoom^FS^XZ";
// The API key is optional — omit the Authorization header if it isn't set.const headers = { "Content-Type": "text/plain" };if (process.env.LABELZOOM_API_KEY) { headers.Authorization = `Bearer ${process.env.LABELZOOM_API_KEY}`;}
const response = await fetch( "https://api.labelzoom.com/api/v2/convert/zpl/to/pdf?label.width=4&label.height=6&dpi=203", { method: "POST", headers, body: zpl, },);
if (!response.ok) { throw new Error(`Conversion failed: ${response.status} ${await response.text()}`);}
await writeFile("label.pdf", Buffer.from(await response.arrayBuffer()));console.log("Wrote label.pdf");Converting a PDF to ZPL
Section titled “Converting a PDF to ZPL”Send the file bytes instead of text:
import { readFile } from "node:fs/promises";
const pdf = await readFile("shipping-label.pdf");
const headers = { "Content-Type": "application/pdf" };if (process.env.LABELZOOM_API_KEY) { headers.Authorization = `Bearer ${process.env.LABELZOOM_API_KEY}`;}
const response = await fetch("https://api.labelzoom.com/api/v2/convert/pdf/to/zpl", { method: "POST", headers, body: pdf,});
const zpl = await response.text();- Call the API from your backend — never expose your key in browser code.
- All endpoint patterns, formats, and parameters are in the quickstart and the Swagger reference.