Print labels from a Vue admin panel
A Vue button calls your backend, which posts the label. Do not call PrintBase from the Vue app. This page matches the Chinese Vue guide.
For Vue admin panels used by warehouse staff
This page in another language: 中文
Overview
Vue's click handler should POST to your API with the row id. The print API key lives in the backend. A Vue plugin that talks to a local port recreates the certificate and private-network problems of other browser bridges.
Pinia or Vuex can store the job id returned by your API. Poll your API for status. Do not poll PrintBase from the browser.
This is the English counterpart of the Chinese Vue label page.
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
// Backend used by the Vue panel
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': rowId,
},
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
Same-origin API
The browser calls your domain. Your domain calls api.printbase.cloud. The agent prints only what you send; it does not fetch the document from the platform for you.
Station select
Bind printer_code only if your backend checks that this user may use that station.
Questions
Can I use axios against PrintBase?
Only from Node. In the browser that exposes the key. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.
Nuxt? in this setup
Use a server route. The Vue page stays a client of that route.
How do I show ESC/POS errors?
Your backend returns the job status and reason code. Vue displays that string.
Multiple tabs?
The idempotency key keeps two tabs from printing two labels of the same row.
Free plan: 100 jobs a month on one computer, no card.