How to auto-print kitchen tickets from your ordering site
When your own ordering site takes an order, print an ESC/POS kitchen ticket through the API. The browser must not hold the API key.
For Restaurants with a custom ordering site and a kitchen printer
Overview
A custom ordering site usually inserts an order and shows a confirmation page. The kitchen ticket has to be printed by the server that inserted the order, not by the guest's phone. There is no print dialog on that phone that can reach the pass printer.
Build ESC/POS for the station (grill, fryer, bar) and POST content_type raw to that station's printer_code. The agent sits on the computer that owns the printer. Choose the station from the items, not from a single hardcoded printer, if the line is split.
Idempotency-Key is the order id. Payment webhooks and your checkout handler must share that key or you will print two tickets for one payment.
Integration steps
- 01
Print in the order-create handler
After the order is committed and paid. Not in client-side JavaScript.
- 02
Split items by station
Each station is a printer_code and a separate job, with the station name in the idempotency key.
- 03
Encode the ticket
Init, header with order number and time, items, modifiers, feed, cut. Match the code page.
- 04
POST raw
Base64 content, copies 1. Do not send the HTML confirmation page.
- 05
Show a failure on the expo screen
If the job fails, the expo display should see the reason code and offer a reprint with a new key.
Node.js
// Ordering API: one station ticket
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': `kitchen:${order.id}:${station}`,
},
body: JSON.stringify({
printer_code: Number(process.env.PRINTER_CODE),
content_type: 'raw',
content: ticket.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
58 mm versus 80 mm
Count columns before you pad prices. The agent will not reflow your bytes. A cut command before line feeds slices the last line.
How you know it printed
Create returns id and status queued. The job then moves queued, dispatched, printing, completed. Failures use reason codes such as AGENT_OFFLINE, PRINTER_OFFLINE, DOWNLOAD_FAILED, PRINT_ERROR, and INVALID_CONTENT. Poll GET /v1/print-jobs/{id}. Webhooks exist on paid plans only, and only for print_job.completed and print_job.failed.
Questions
Can the confirmation page call the local agent?
Not from your public origin. Local printing on 127.0.0.1:17891 allows localhost and printbase.cloud origins only. Use the cloud API.
Online orders and in-store tickets on one printer?
Yes, if they target the same printer_code. Include a source line on the ticket so the kitchen can tell them apart.
What if the printer is a Star TSP100?
Many TSP100 units are happiest with the OS driver and a PDF. If raw text prints as garbage, send a small PDF instead. See the Star printer page.
Do I need a plugin?
No. It is your handler and the print API. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.
Free plan: 100 jobs a month on one computer, no card.