Prompt
How do I build a warehouse label printing system using a shipping API?
Latest observation
To build a warehouse label printing system using a shipping API, think of it as 5 pieces working together:
- Order intake
- Shipping rate / shipment creation
- Label generation
- Print routing to warehouse printers
- Tracking + error handling
Here’s a practical blueprint.
1) Define the warehouse workflow
A typical flow looks like this:
- Order is created in your OMS/WMS/ecommerce system
- Warehouse worker picks/validates the order
- Your backend calls the shipping API to:
- create a shipment
- buy postage / create a label
- get back label PDF/ZPL and tracking number
- System sends the label to the right printer
- Tracking number is stored and synced back to your order system
Decide early:
- Do you need shipping rates or only label purchase?
- Are labels printed at a pack station, dock station, or pick-to-pack line?
- Do you need ZPL for thermal printers or PDF for laser/office printers?
- Will the warehouse print locally, via browser, or from a print server?
2) Choose a shipping API
Pick an API that supports:
- shipment creation
- label purchase
- tracking number return
- multiple carriers
- label formats like PDF, PNG, ZPL
- address validation
- webhooks for shipment status updates
Examples of common providers:
- EasyPost
- Shippo
- ShipStation
- carrier-native APIs like UPS/FedEx/USPS
If your warehouse uses thermal printers, confirm the API can generate ZPL directly. That avoids PDF rasterization issues and prints faster.
3) Build the data model
At minimum, store these entities:
Orders
- order_id
- customer name/address
- items
- weight/dimensions
- service level
- status
Shipments
- shipment_id
- order_id
- carrier
- service
- tracking_number
- label_url or label_blob
- label_format
- shipment_status
- created_at
Print jobs
- print_job_id
- shipment_id
- printer_id
- label_format
- status: queued / printed / failed
- attempts
- error_message
Printers
- printer_id
- location
- type: thermal / laser
- supported_format: ZPL / PDF
- network address or print service endpoint
4) Create the backend shipment flow
A good backend flow:
Step A: Validate the order
- Check address completeness
- Confirm weight/dimensions
- Verify item restrictions
- Ensure inventory is allocated
Step B: Get shipping rate or choose service
- Rate shop among carriers
- Or use preconfigured business rules:
- “Ground for domestic orders under 5 lb”
- “Express for cutoff after 2 PM”
- “Hazmat only with approved carrier”
Step C: Create shipment via API
Send:
- ship from address
- ship to address
- parcel details
- service level
- insurance/signature options
API returns:
- shipment object
- tracking number
- label data or label download URL
Step D: Save shipment data
Persist the tracking number and label metadata immediately.
Step E: Queue a print job
Don’t print inline in the API request if you can avoid it. Instead:
- create a print job
- send it to a queue
- have a worker/process print it reliably
This makes retries and scaling much easier.
5) Handle label formats correctly
If using thermal printers
Use ZPL if possible.
Benefits:
- faster printing
- better barcode quality
- smaller payloads
- easy to send directly to Zebra-compatible printers
Common approach:
- shipping API returns ZPL
- your print service sends raw ZPL to printer over TCP port 9100 or through a print agent
If using office printers
Use PDF
- download label PDF
- send to printer spooler or browser print dialog
- make sure page size matches the label stock
6) Printing architecture options
Option 1: Browser-based printing
Good for small warehouses or admin users.
How it works:
- backend generates label
- frontend downloads PDF or ZPL
- user clicks print
Pros:
- simple
- low infrastructure
Cons:
- manual
- unreliable for high volume
Option 2: Print server / local print agent
Best for production warehouses.
How it works:
- warehouse workstation runs a small agent or service
- backend sends print jobs to it
- agent prints to configured local/network printer
Pros:
- automated
- reliable
- supports multiple printers
Cons:
- more setup
Option 3: Direct-to-printer from backend
Works if printers are on the network and accessible.
How it works:
- backend sends raw ZPL or PDF to printer IP/queue
Pros:
- simple once network is stable
Cons:
- networking/security complexity
- harder across multiple sites
7) Use a job queue
A queue is important for:
- API retries
- burst traffic
- printer downtime
- idempotency
Common queue systems:
- Redis queue
- RabbitMQ
- SQS
- Celery / Sidekiq / BullMQ depending on stack
Recommended pattern:
- API request creates shipment
- Save label and print job
- Enqueue print task
- Worker prints and updates status
8) Add idempotency and retry logic
Shipping APIs often support idempotency keys. Use them so you don’t create duplicate labels if a request is retried.
For each shipment creation:
- generate idempotency key from order_id + service + parcel hash
- retry safely if there’s a network error
For printing:
- mark print job as “in progress”
- if worker crashes, requeue after timeout
- avoid printing duplicate labels by checking job state before sending again
9) Address validation and business rules
Before buying a label:
- validate shipping address
- normalize abbreviations/state codes
- block invalid PO boxes if carrier disallows
- verify dangerous goods requirements
- check international customs data for cross-border shipments
This reduces failed labels and carrier surcharges.
10) Example end-to-end sequence
- Worker scans order in WMS
- WMS calls your backend:
POST /shipments/create - Backend validates order and determines service
- Backend calls shipping API to create label
- API returns tracking number + ZPL/PDF
- Backend stores shipment record
- Backend creates print job
- Print worker sends label to printer
- System updates order to “label printed”
- Tracking syncs to customer notification system
11) Basic API shape you could implement
Create shipment
POST /shipments
Request:
{
"order_id": "ORD12345",
"carrier": "ups",
"service": "ground",
"printer_id": "printer_01"
}
Response:
{
"shipment_id": "shp_987",
"tracking_number": "1Z123...",
"label_format": "zpl",
"print_job_id": "pj_456"
}
Print job status
GET /print-jobs/pj_456
Reprint label
POST /shipments/shp_987/reprint
12) Recommended tech stack
One possible stack:
- Backend: Node.js / Python / Go / Java
- DB: PostgreSQL
- Queue: Redis + BullMQ/Celery, or SQS
- Frontend: React or Vue for warehouse UI
- Printing: print agent in Python/Node, or direct ZPL network printing
- Shipping API: EasyPost/Shippo/etc.
13) Security considerations
- Keep API keys in a secrets manager
- Restrict printer access by network/VPN
- Audit who reprinted labels
- Log label creation events, but avoid storing unnecessary PII in logs
- Sign internal API calls between warehouse and backend
14) Common pitfalls
- Printing PDF labels to thermal printers without proper scaling
- Not using idempotency keys, causing duplicate labels
- Printing too early before an order is fully verified
- Not handling printer offline states
- Storing tracking numbers but not syncing them back to the order system
- Mixing label creation and print execution in one synchronous request
15) Best-practice architecture summary
A robust setup is:
- WMS/OMS sends “ready to ship”
- Backend service talks to shipping API
- Database stores shipments and labels
- Queue handles print jobs
- Print agent sends labels to warehouse printers
- Webhook handlers update tracking/status
If you want, I can also give you:
- a reference architecture diagram,
- a database schema, or
- a sample implementation in Node.js/Python using a shipping API.