Prompt
How do I handle international shipping labels and customs forms with an API?
Latest observation
To handle international shipping labels and customs forms with an API, you typically need to integrate a shipping provider or shipping aggregator API that supports:
- rate shopping
- label generation
- customs data
- tracking
- commercial invoices / CN22 / CN23 forms
Typical flow
-
Create a shipment/order in your system
- Sender address
- Recipient address
- Package details
- Contents of the shipment
- Declared value and currency
- Harmonized codes / HS codes
- Country of origin
- Incoterms if needed
-
Send shipment data to the shipping API
- The API validates whether the destination is international
- It determines required customs data based on destination, carrier, and service
-
Receive label + customs documents
- Usually returned as:
- ZPL / EPL for thermal printers
- base64-encoded label/document files
- Often there are separate documents:
- shipping label
- commercial invoice
- customs declaration form
- Usually returned as:
-
Print and attach documents
- Labels are typically placed on the parcel
- Customs forms may need to be attached in a pouch or printed separately depending on carrier and destination
-
Track shipment
- Store carrier tracking number and shipment ID
- Use webhooks or polling for tracking updates
Data you usually need for customs
For international shipments, APIs often require:
- Item description: clear, non-generic description
- Quantity
- Item value
- Currency
- Weight
- HS code / tariff code
- Country of origin
- Item category: gift, commercial sample, sale, return, document, etc.
- Reason for export
- Sender and recipient tax IDs if required
- Declared contents and total invoice value
Important implementation details
1. Validate destination rules
Different countries require different customs fields. Your API integration should:
- check whether customs docs are required
- enforce mandatory fields
- adjust form type by carrier and destination
2. Handle commercial invoices correctly
For many carriers, the API can generate a commercial invoice automatically from shipment contents. Make sure:
- item descriptions are specific
- values add up correctly
- package totals match line-item totals
- taxes/duties settings are explicit
3. Support document formats
Your system should be able to handle:
- PDF downloads
- base64-encoded documents
- multiple pages
- thermal printer formats like ZPL
4. Print customs forms separately when needed
Some shipments require:
- label on the box
- invoice in a transparent pouch
- customs declaration attached externally
5. Use webhooks for status changes
International shipments can have extra events:
- customs clearance started
- held by customs
- duties paid
- returned to sender
Example API request shape
A shipment request commonly looks like this:
{
"shipper": {
"name": "Acme Inc.",
"address1": "123 Main St",
"city": "New York",
"state": "NY",
"postal_code": "10001",
"country": "US"
},
"recipient": {
"name": "Jean Dupont",
"address1": "45 Rue Example",
"city": "Paris",
"postal_code": "75001",
"country": "FR"
},
"parcel": {
"weight": 2.5,
"length": 30,
"width": 20,
"height": 10,
"weight_unit": "kg",
"dimension_unit": "cm"
},
"customs": {
"contents_type": "merchandise",
"invoice_number": "INV-10045",
"items": [
{
"description": "Cotton T-shirt",
"quantity": 2,
"value": 25.00,
"currency": "USD",
"weight": 0.4,
"origin_country": "US",
"hs_code": "610910"
}
]
}
}
Example response shape
{
"shipment_id": "shp_12345",
"tracking_number": "1Z999AA10123456784",
"label_url": "https://example.com/label.pdf",
"customs_document_url": "https://example.com/customs.pdf",
"status": "created"
}
Practical tips
- Use address validation before creating labels.
- Keep a mapping of country-specific customs requirements.
- Store all generated documents for audit and reprinting.
- Normalize units and currencies before sending data to the API.
- If shipping from software like Shopify, ERP, or a warehouse system, build a middleware layer to transform order data into carrier-ready shipment data.
Common API providers
Depending on your needs, you can use:
- Shippo
- EasyPost
- Easyship
- ShipEngine
- Direct carrier APIs like:
- UPS
- FedEx
- DHL
- USPS (limited for international customs features)
If you want, I can also show:
- a real API example for one provider, or
- a database schema / backend design for storing international shipment and customs data.