Back to blog

How to monitor DHL shipments automatically

·5 min read

If you ship products with DHL in Europe, you already know the pain of manually checking tracking pages. A customer writes in asking about their order, you open the DHL portal, paste the tracking number, wait for the page to load, and read the status. Multiply that by fifty or a hundred parcels a day and you have lost an entire person's worth of productivity to copy-paste work.

There is a better way. DHL provides tracking APIs that let you query shipment status programmatically. Combined with an intelligent polling strategy and exception detection logic, you can build a system that watches every parcel in your pipeline and only surfaces the ones that need human attention.

Understanding the DHL Tracking API

DHL offers the Shipment Tracking API (part of the DHL Developer Portal) that returns structured JSON data for any tracking number. The response includes the current status, a history of tracking events, estimated delivery dates, and any exception flags. You authenticate with API keys obtained through the DHL Developer Portal.

A typical API call looks like this:

bash
curl -X GET "https://api-eu.dhl.com/track/shipments?trackingNumber=00340434161094042684" \
  -H "DHL-API-Key: your_dhl_api_key"

The response contains a shipments array with status objects, each carrying a statusCode (like transit, delivered, or failure) and a description field with the human-readable event text. The events array gives you the full tracking history with timestamps and location data.

Polling strategies that scale

The simplest approach is to poll every tracking number on a fixed interval — say, every 30 minutes. This works fine for a handful of shipments, but it falls apart quickly. At 500 active shipments polled every 30 minutes, you are making 24,000 API calls per day. DHL rate limits will catch up with you, and most of those calls will return the same status you already have.

A smarter strategy adjusts polling frequency based on shipment age and status:

  • 1.First 24 hours after creation: Poll every 2 hours. The shipment is likely still being processed and picked up. Frequent checks add little value.
  • 2.In transit, days 1-3: Poll every 30-60 minutes. This is where most exceptions surface — missed scans, sort facility delays, customs holds.
  • 3.In transit, past expected delivery: Poll every 15 minutes. The shipment is overdue. You want to know immediately if it moves or if an exception event appears.
  • 4.Delivered or returned: Stop polling. Move the shipment to a terminal state and free up the slot.

This tiered approach can reduce API call volume by 60-70% compared to a flat polling interval while improving detection speed for the shipments that actually need attention.

Exception detection patterns

Not every status change is worth acting on. A shipment moving from one sort facility to another is routine. What you want to catch are the events that indicate a problem the customer will notice:

  • Failed delivery attempt --The driver tried and failed to deliver. You have a narrow window (usually one business day) before the parcel goes to a pickup point or gets returned. Proactive outreach to the customer here can save the delivery.
  • Shipment on hold / customs clearance --Common for cross-border EU shipments. The parcel is sitting at customs waiting for documentation or duty payment. If you ship internationally, you need to flag these within hours, not days.
  • Return to sender initiated --The carrier has given up on delivery and is sending the parcel back. This is often the result of multiple failed attempts or an unresolvable address issue. You need to know immediately to arrange a re-shipment or refund.
  • No scan for 48+ hours --The tracking events simply stop. The parcel might be lost, misrouted, or sitting in an overwhelmed facility. This pattern is not an explicit exception in the DHL API — you have to detect it yourself by comparing the last event timestamp against the current time.
typescript
// Example: detecting stale shipments
function isStale(lastEventAt: Date, thresholdHours: number = 48): boolean {
  const elapsed = Date.now() - lastEventAt.getTime();
  return elapsed > thresholdHours * 60 * 60 * 1000;
}

// Example: mapping DHL status codes to severity
function classifyException(statusCode: string): 'critical' | 'warning' | 'info' {
  const critical = ['failure', 'returned'];
  const warning = ['customs', 'on-hold', 'delivery-attempt-failed'];

  if (critical.includes(statusCode)) return 'critical';
  if (warning.includes(statusCode)) return 'warning';
  return 'info';
}

Putting it together: a monitoring pipeline

A production-grade monitoring system connects these pieces into a pipeline:

  1. Ingestion -- Shipments enter the system via CSV upload or API call with tracking numbers and customer references.
  2. Scheduling -- A cron job or task queue selects shipments due for a status check based on their polling tier.
  3. Fetching -- The system calls the DHL API, handling rate limits with exponential backoff and retry logic.
  4. Diffing -- The new status is compared against the stored status. If nothing changed, the shipment is marked as checked and the next poll is scheduled.
  5. Exception detection -- Changed statuses are run through the classification logic. Exceptions trigger notifications via email, Slack, webhooks, or other channels.
  6. Triage -- Flagged shipments land on a dashboard where operations staff can review them, take action, and mark them resolved.

Building this from scratch is feasible but involves significant ongoing maintenance — keeping up with DHL API changes, managing rate limits across multiple DHL API keys, handling edge cases in status parsing, and scaling the polling infrastructure as shipment volume grows.

Or use ShipTriage

ShipTriage implements this entire pipeline as a managed service. You import shipments via CSV or REST API, and ShipTriage handles the polling, exception detection, priority assignment, and notifications. The triage dashboard gives your operations team a single view of every shipment that needs attention, sorted by urgency. All data stays in the EU, fully GDPR-compliant.

If you are shipping with DHL in Europe and spending time manually checking tracking statuses, automated monitoring is not optional — it is the baseline for professional e-commerce operations.

Start monitoring your DHL shipments automatically

Free plan includes 10 active shipments. No credit card required.

Get started free