Prompt
How do I send tracking updates to customers from shipping webhooks?
Latest observation
To send tracking updates from shipping webhooks, the basic flow is:
- Receive webhook events from your shipping carrier/platform
- Parse the event payload
- Map the event to a customer-facing status
- Store/update shipment tracking in your database
- Notify the customer by email/SMS/push/in-app message
- Deduplicate events so customers don’t get spammed
Typical webhook events to handle
Depending on the carrier or shipping API, you may get events like:
shipment.createdshipment.picked_upin_transitout_for_deliverydeliveredexceptiondelayreturn_to_sender
Recommended implementation
1) Create a webhook endpoint
Your server should expose an HTTPS endpoint, for example:
POST /webhooks/shipping
The carrier sends tracking updates to this endpoint.
2) Verify the webhook
Before using the payload, verify it came from the shipping provider:
- HMAC signature header
- webhook secret
- timestamp checks
- source IP checks if supported
This prevents fake updates.
3) Extract shipment and status information
A webhook payload might look like:
{
"tracking_number": "1Z999AA10123456784",
"status": "in_transit",
"event_time": "2026-11-04T12:34:56Z",
"carrier": "UPS",
"location": "Chicago, IL"
}
4) Update your shipment record
Use the tracking number or shipment ID to find the order in your database and update fields like:
- current_status
- last_event_time
- last_location
- delivery_estimate
- carrier_event_id
5) Send the customer notification
Once the shipment status changes, trigger your notification system:
- Email: “Your package is out for delivery”
- SMS: “Your order has been delivered”
- Push notification: “Delay detected for your shipment”
6) Avoid duplicate notifications
Carriers often resend webhooks or send multiple events with the same status. Store the event ID or hash of:
- tracking number
- status
- event timestamp
Only notify if the event is new.
Example logic
Pseudo-flow:
def shipping_webhook(request):
verify_signature(request)
event = request.json
tracking = event["tracking_number"]
status = event["status"]
event_id = event.get("event_id")
if already_processed(event_id):
return 200
shipment = find_shipment_by_tracking(tracking)
if not shipment:
return 404
shipment.status = status
shipment.last_event_time = event["event_time"]
save(shipment)
if status_changed_to_customer_notifyable(status):
send_customer_notification(shipment.customer_id, status)
mark_processed(event_id)
return 200
Good customer notification rules
Not every webhook should trigger a message. Usually notify on:
- picked up
- out for delivery
- delivered
- delayed / exception
- failed delivery attempt
Avoid notifying on every minor scan unless you want very granular updates.
Best practices
- Idempotency: handle duplicate webhook deliveries safely
- Queue notifications: send emails/SMS asynchronously, not inside the webhook request
- Fallback polling: if webhooks fail, periodically poll carrier tracking APIs
- Timezone normalization: store all timestamps in UTC
- Customer preferences: let users choose email vs SMS vs push
- Rate limiting: avoid too many notifications for frequent scans
Example architecture
Shipping provider webhook → Webhook handler → Database update → Message queue → Notification service → Customer
This is better than sending notifications directly from the webhook handler, because it’s more reliable and scalable.
If you want, I can also give you:
- a Node.js/Express example
- a Python/FastAPI example
- a database schema for tracking events
- or a full end-to-end architecture diagram
Brands