Prompt
How do I build a shipping integration that updates orders automatically?
Latest observation
To build a shipping integration that automatically updates orders, you generally need 5 parts:
- Trigger when an order is ready to ship
- Send order data to the shipping carrier/fulfillment system
- Receive shipment and tracking updates
- Update your order record automatically
- Handle errors, retries, and status changes
Here’s a practical blueprint.
1) Define the workflow
Typical lifecycle:
- Order created in your store
- Order paid / approved
- Order sent to shipping provider or warehouse
- Shipment created
- Tracking number received
- Order status updated to
shipped - Tracking events update to
in transit,delivered, etc.
Decide which systems are involved:
- Your ecommerce platform
- Shipping carrier API, or shipping aggregator
- Warehouse/3PL system
- Your internal order database
2) Choose the integration pattern
Option A: Webhooks first
Best if the shipping provider can call your system when status changes.
- Your app exposes an endpoint like:
POST /webhooks/shipping
- Provider sends events:
shipment.createdshipment.updateddelivery.delivered
Pros: real-time, efficient
Cons: you must verify and secure webhook delivery
Option B: Polling
Your system regularly checks the shipping API for updates.
- Run a scheduled job every few minutes
- Fetch shipment statuses
- Update orders as needed
Pros: simpler with some APIs
Cons: less real-time, more API usage
Option C: Hybrid
Use webhooks for real-time updates and polling as fallback.
3) Data you need to map
At minimum, maintain:
order_idexternal_shipment_idtracking_numbercarrierorder_statusshipment_statuslast_status_updatetracking_url
Example status mapping:
| Shipping event | Internal order status |
|---|---|
| label_created | processing |
| handed_to_carrier | shipped |
| in_transit | in_transit |
| out_for_delivery | out_for_delivery |
| delivered | delivered |
| exception | delayed / issue |
4) Build the shipping API integration
If the shipping provider offers an API, you’ll usually do:
A. Create shipment
Send:
- recipient address
- package dimensions/weight
- order reference
- service level
Receive:
- shipment ID
- tracking number
- label URL
B. Store shipment details
Save them in your database so your system can match future updates.
C. Subscribe to events or configure webhooks
Register callback URLs with the provider.
5) Implement automatic order updates
When a shipment event arrives:
- Validate the webhook signature
- Parse the event
- Find the related order using
shipment_idortracking_number - Update the shipment record
- Update the order status
- Write an audit log
- Notify the customer if needed
Example logic:
if event.type == "shipment.delivered":
order = find_order_by_tracking(event.tracking_number)
order.status = "delivered"
order.delivered_at = event.timestamp
save(order)
6) Make it reliable
Use idempotency
Webhook events can be delivered more than once.
Store event IDs and ignore duplicates.
Add retries
If updating your database or platform fails, retry safely.
Queue processing
Don’t do heavy work directly in the webhook request.
Instead:
- receive webhook
- verify it
- enqueue a job
- process asynchronously
Log everything
Keep logs for:
- incoming events
- API requests/responses
- status transitions
- failures
7) Secure the integration
- Use HTTPS
- Verify webhook signatures or shared secrets
- Restrict allowed IPs if supported
- Store API keys securely
- Validate payloads before processing
8) Sync back to your store or ERP
If you use Shopify, WooCommerce, Magento, or a custom order system, update:
- fulfillment status
- tracking number
- carrier name
- shipping confirmation email
Often this means calling your ecommerce platform’s order update API.
9) Handle edge cases
Plan for:
- partial shipments
- split orders
- cancelled shipments
- returned packages
- address corrections
- delayed or exception statuses
- missing tracking numbers
10) Test end-to-end
Test scenarios:
- shipment created
- tracking number assigned
- delivery confirmed
- duplicate webhook
- invalid webhook signature
- API timeout
- carrier exception status
Use sandbox/test mode if the provider offers it.
Simple architecture
Order Created
↓
Fulfillment/Shipping API
↓
Shipment + Tracking Number Created
↓
Webhook / Polling Update
↓
Your Integration Service
↓
Update Order DB / Ecommerce Platform
↓
Notify Customer
Suggested tech stack
A common setup:
- Backend: Node.js, Python, Java, Ruby, or PHP
- Queue: Redis, SQS, RabbitMQ
- Database: PostgreSQL/MySQL
- Webhook endpoint: REST API
- Scheduler: cron or background worker
- Monitoring: logs + alerting
Minimal implementation plan
- Create a shipment table in your DB
- Build shipping label creation API call
- Store tracking number and shipment ID
- Add webhook endpoint for shipping updates
- Map provider events to internal statuses
- Update the order record automatically
- Add retries, deduplication, and logging
If you want, I can also give you:
- a sample database schema
- a Node.js webhook example
- a Python/FastAPI example
- or a Shopify/WooCommerce-specific integration design