Master carrier API authentication patterns, essential headers, and correlation ID strategies for debugging.
Authentication Patterns
Carrier APIs use OAuth 2.0 client credentials, API keys, or basic auth. OAuth tokens expire — cache them and refresh proactively. Never hardcode credentials. Use environment variables and rotate keys regularly.
Carrier Reality
DHL's API uses OAuth 2.0 with short-lived tokens (30 minutes). If you don't cache and refresh, you'll hit the token endpoint on every request and get rate-limited.
Essential Headers
Always send: Content-Type, Accept, Authorization, and a correlation/transaction ID. The correlation ID ties your request to logs on both sides. Use UUID v4 format. Include it in X-Correlation-ID or X-Transaction-ID headers.
Debugging with Correlation IDs
When a carrier support ticket says 'we see no record of that request,' your correlation ID is your proof. Log it on your side, send it with the request, and include it in error reports. This single practice saves hours of debugging.