How to auto-print receipts from Supabase or Firebase
Print a receipt from a Supabase database webhook or a Firebase function. The function holds the API key. No native plugin is included.
For SaaS developers whose orders land in Supabase or Firebase
Overview
A row insert is not a printer. Supabase database webhooks and Firebase functions are the moment you have an order and a place to keep a secret. PrintBase does not ship a Supabase or Firebase extension.
The function reads the new order, builds ESC/POS or a PDF, and POSTs /v1/print-jobs to the printer_code for that tenant or store. Multi-tenant apps should store printer_code on the tenant row and refuse to print if it is missing.
Idempotency-Key is the order primary key. Webhooks retry. Do not mint a random UUID per attempt or you will print duplicates.
Integration steps
- 01
Trigger on insert or on a status column
Print when the order is payable, not when a draft row is created.
- 02
Read printer_code from the tenant
The client must not send an arbitrary code unless you authorize it. Prefer the value stored on the server.
- 03
Build the receipt in the function
ESC/POS raw or PDF. Encode text for the printer. Use POST /v1/print-jobs with Authorization: Bearer and the printer_code from GET /v1/printers.
- 04
POST with the order id as the key
Authorization from the function's environment, never from the mobile app.
- 05
Write job id back to the row
A column your support tools can show. Update it when you poll status.
Node.js
// Supabase or Firebase function: receipt for a new order
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': order.id,
},
body: JSON.stringify({
printer_code: Number(process.env.PRINTER_CODE),
content_type: 'raw',
content: Buffer.from(receipt).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
Do not call the API from the client SDK
Supabase and Firebase client keys are not a place to hide a print API key. The printer call belongs in a function or a webhook handler.
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
Is there a Supabase integration?
No extension. A database webhook to a function is enough. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.
Firebase Auth users printing their own receipts?
The function checks the user, then uses the server API key. The user's ID token is not a PrintBase key.
How do I isolate tenants?
Store printer_code per tenant. For stronger isolation, use one PrintBase organization per tenant via the Enterprise API (POST /v1/enterprise/orgs and a per-org API key). That API is for Enterprise accounts.
The function timed out.
The print POST is a short HTTPS call. Do not sleep until the printer finishes inside the function if the platform has a short limit. Poll later.
Free plan: 100 jobs a month on one computer, no card.