Prompt
How do I create shipments and print labels from an API?
Latest observation
Oct 5, 2026
OpenAI APIWeb search: off
To create shipments and print labels from an API, the general flow is:
- Create a shipment / parcel / order
- Rate it (optional but common)
- Buy / purchase the label
- Download or print the label
- Track the shipment
The exact endpoints vary by carrier or shipping platform, but the pattern is usually the same.
Typical API flow
1) Authenticate
Most shipping APIs require an API key or OAuth token.
Example:
Authorization: Bearer YOUR_API_TOKEN
Content-Type: application/json
2) Create a shipment request
You send details like:
- Sender address
- Recipient address
- Package weight and dimensions
- Service level
- Insurance / customs info if needed
Example JSON:
{
"ship_to": {
"name": "Jane Doe",
"address1": "123 Main St",
"city": "Austin",
"state": "TX",
"postal_code": "78701",
"country": "US"
},
"ship_from": {
"name": "My Warehouse",
"address1": "500 Warehouse Rd",
"city": "Dallas",
"state": "TX",
"postal_code": "75201",
"country": "US"
},
"package": {
"weight": 2.5,
"weight_unit": "lb",
"length": 10,
"width": 6,
"height": 4,
"dimension_unit": "in"
},
"service": "ground"
}
3) Get rates
The API returns available shipping options and prices.
Example response:
{
"rates": [
{
"carrier": "UPS",
"service": "Ground",
"amount": "12.45",
"currency": "USD",
"estimated_delivery": "2026-10-08"
},
{
"carrier": "FedEx",
"service": "Home Delivery",
"amount": "13.10",
"currency": "USD",
"estimated_delivery": "2026-10-07"
}
]
}
4) Purchase the label
Once you choose a rate, submit a “buy label” or “create shipment” request.
The response usually includes:
- Shipment ID
- Tracking number
- Label URL or label binary/base64
- Carrier details
Example response:
{
"shipment_id": "shp_12345",
"tracking_number": "1Z999AA10123456784",
"label_url": "https://api.example.com/labels/label_123.pdf"
}
5) Print the label
Depending on the API, labels may be returned as:
- PDF URL — download and print
- Base64 PDF — decode and print
- ZPL/PNG — send directly to printer or render first
If it’s a PDF URL:
curl -o label.pdf "https://api.example.com/labels/label_123.pdf"
If it’s base64:
import base64
label_b64 = response["label"]
with open("label.pdf", "wb") as f:
f.write(base64.b64decode(label_b64))
Example using a generic REST API in Python
import requests
API_TOKEN = "YOUR_API_TOKEN"
BASE_URL = "https://api.example.com"
headers = {
"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json"
}
shipment_data = {
"ship_to": {
"name": "Jane Doe",
"address1": "123 Main St",
"city": "Austin",
"state": "TX",
"postal_code": "78701",
"country": "US"
},
"ship_from": {
"name": "My Warehouse",
"address1": "500 Warehouse Rd",
"city": "Dallas",
"state": "TX",
"postal_code": "75201",
"country": "US"
},
"package": {
"weight": 2.5,
"weight_unit": "lb",
"length": 10,
"width": 6,
"height": 4,
"dimension_unit": "in"
},
"service": "ground"
}
# Create shipment
resp = requests.post(f"{BASE_URL}/shipments", json=shipment_data, headers=headers)
resp.raise_for_status()
data = resp.json()
print("Shipment created:", data)
print("Tracking number:", data.get("tracking_number"))
print("Label URL:", data.get("label_url"))
Printing the label
If the API gives you a PDF:
- Open it and print from your computer/server
- Or send it to a label printer
- For thermal printers, many APIs support ZPL format
Example label formats:
- PDF: good for regular printers
- ZPL: best for Zebra thermal printers
- PNG: sometimes supported for preview
Important things to check
- Label size: 4x6 is common for shipping labels
- Printer compatibility: PDF vs ZPL
- International shipments: customs forms required
- Address validation: many APIs provide it
- Void/cancel endpoint: useful if you create a label by mistake
If you tell me the shipping provider
If you want, I can give you exact code for:
- Shippo
- EasyPost
- UPS
- FedEx
- DHL
- USPS
- or your own custom API
If you share the provider and language you’re using, I can write a working example.