How to auto-print barcode labels from Google Sheets
Use Apps Script to send barcode labels from a sheet to a printer. No Sheets add-on is included; UrlFetchApp calls the API.
For Teams who maintain SKUs in a spreadsheet and print labels from a row
Overview
Google Sheets will not open a thermal printer. Apps Script can. A custom menu or an installable onEdit trigger reads the selected rows, builds ZPL or a PDF, and calls UrlFetchApp against POST /v1/print-jobs. PrintBase does not publish a Sheets add-on.
Prefer ZPL or TSPL for barcodes (content_type raw) so the printer draws the bars. A PDF of a barcode is content_type pdf and often scans worse on thermal heads. The script property store holds the API key, not a cell.
Idempotency-Key sheet row id plus a print count column. Bumping the count reprints. Leaving it unchanged makes a second click a replay.
Integration steps
- 01
Store the API key in Script Properties
Not in a sheet cell. Editors of the sheet should not receive the key if you can avoid sharing the project.
- 02
Build one label per selected row
ZPL with ^BC or ^BQ for a Zebra. PDF if the printer is a DYMO or Brother that does not speak ZPL.
- 03
UrlFetchApp POST
Authorization Bearer, content_type, base64 payload, printer_code, Idempotency-Key.
- 04
Write job id and status into columns
So the sheet shows queued or the error body. Use POST /v1/print-jobs with Authorization: Bearer and the printer_code from GET /v1/printers.
- 05
Do not use a simple onEdit for every cell
Print from a menu or a checkbox column so casual edits do not burn labels.
Node.js
// Equivalent of the Apps Script payload for one ZPL label row
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': `sheet:${rowId}:${printCount}`,
},
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 Sheets barcode 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.
DYMO and Brother rows
Those printers usually want a PDF or their own driver graphics, not ZPL. If the sheet's printer is a LabelWriter, render PDF and set content_type pdf. Check the printer pages for those models.
Questions
Is there a Google Workspace add-on?
No. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.
Can IMPORTRANGE trigger a print?
Not reliably, and you should not print from every recalculation. Use an explicit action.
203 versus 300 dpi?
If you emit ZPL, set dot dimensions for the printer you stored on that row. The API does not know the dpi.
Apps Script quotas?
UrlFetchApp has Google quotas that are separate from PrintBase job quotas. The free PrintBase plan is 100 jobs a month on one computer.
Free plan: 100 jobs a month on one computer, no card.