> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Dhl Api

> LoT connector for DHL Shipment Tracking Unified: track shipments across DHL divisions and manage Tracking Push subscriptions with a DHL API key

Technical Preview

## Overview

Client-mode REST API connectors for the DHL API Developer Portal: Shipment Tracking Unified (every DHL division) with Tracking Push subscriptions, Location Finder service points, DHL Express MyDHL API (rates, landed cost, shipments and labels, pickups, tracking, proof of delivery, paperless trade uploads) and Post & Parcel Germany (Parcel DE Shipping, Pickup and Returns with OAuth); purchases marked; companion server connector for DHL Tracking Push webhooks.

This is one of the templates in the DHL API Developer Portal REST API app (`dhl-api-developer-portal`). Deploy it alongside the other connectors of that app when they depend on each other (for example a token connector plus an API connector).

## Auth

Per product: DhlApi + DhlLocationFinder header DHL-API-Key (developer.dhl.com app key); MyDhlExpress HTTP Basic MyDHL username:password (from DHL Express, not the portal key) + x-version 3.3.3 + Message-Reference; DhlParcelDeAuth OAuth 2.0 password grant (form grant\_type=password, username, password = GKP system user, client\_id = API key, client\_secret = API secret; reply access\_token Bearer, expires\_in 1799, no refresh token); DhlParcelDe Authorization: Bearer only (bearer + dhl-api-key together -> 401). Every event sends User-Agent: Coreflux-Broker.

Auth headers used by the template: `DHL-API-Key: {value.json.api_key}`.

## Template parameters

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the Dhl Api connector | no |
| `BaseUrl` | string | Dhl Api base URL without trailing slash (e.g. [https://api-eu.dhl.com](https://api-eu.dhl.com)) | yes |

`BASE_ADDRESS` default: `https://api-eu.dhl.com`.

## Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `TrackShipment` | GET | `/track/shipments?{value.json.query}` | `fleet/dhl/shipment-tracking/get` | `fleet/dhl/shipment-tracking/get/response` | `api_key`, `query` |
| `CreateTrackingSubscription` | POST | `/tracking/push/v1/subscription` | `fleet/dhl/tracking-subscription/create` | `fleet/dhl/tracking-subscription/create/response` | `api_key`, `body` |
| `ActivateTrackingSubscription` | POST | `/tracking/push/v1/subscription/{value.json.id}` | `fleet/dhl/tracking-subscription/activate` | `fleet/dhl/tracking-subscription/activate/response` | `api_key`, `hook_secret`, `id` |
| `GetTrackingSubscription` | GET | `/tracking/push/v1/subscription/{value.json.id}` | `fleet/dhl/tracking-subscription/get` | `fleet/dhl/tracking-subscription/get/response` | `api_key`, `id` |
| `ListTrackingSubscriptions` | GET | `/tracking/push/v1/subscriptions` | `fleet/dhl/tracking-subscription/list` | `fleet/dhl/tracking-subscription/list/response` | `api_key` |
| `DeleteTrackingSubscription` | DELETE | `/tracking/push/v1/subscription/{value.json.id}` | `fleet/dhl/tracking-subscription/delete` | `fleet/dhl/tracking-subscription/delete/response` | `api_key`, `hook_secret`, `id` |

## Deploy

Get the template card (JSON with `template` and `metadata`) from the broker, then deploy the connector:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-connectorCode DHL_API"
```

The deployable connector from the REST API app, with `BASE_ADDRESS` already filled in:

```lot theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
DEFINE CONNECTOR DhlApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://api-eu.dhl.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT TrackShipment
        WITH SOURCE_TOPIC "fleet/dhl/shipment-tracking/get"
        WITH DESTINATION_TOPIC "fleet/dhl/shipment-tracking/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/track/shipments?{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker"
            ADD "DHL-API-Key" "{value.json.api_key}"
    ADD EVENT CreateTrackingSubscription
        WITH SOURCE_TOPIC "fleet/dhl/tracking-subscription/create"
        WITH DESTINATION_TOPIC "fleet/dhl/tracking-subscription/create/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/tracking/push/v1/subscription"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker"
            ADD "DHL-API-Key" "{value.json.api_key}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.body}"
    ADD EVENT ActivateTrackingSubscription
        WITH SOURCE_TOPIC "fleet/dhl/tracking-subscription/activate"
        WITH DESTINATION_TOPIC "fleet/dhl/tracking-subscription/activate/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/tracking/push/v1/subscription/{value.json.id}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker"
            ADD "DHL-API-Key" "{value.json.api_key}"
            ADD "DHL-API-Hook-Secret" "{value.json.hook_secret}"
        WITH BODY ""
    ADD EVENT GetTrackingSubscription
        WITH SOURCE_TOPIC "fleet/dhl/tracking-subscription/get"
        WITH DESTINATION_TOPIC "fleet/dhl/tracking-subscription/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/tracking/push/v1/subscription/{value.json.id}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker"
            ADD "DHL-API-Key" "{value.json.api_key}"
    ADD EVENT ListTrackingSubscriptions
        WITH SOURCE_TOPIC "fleet/dhl/tracking-subscription/list"
        WITH DESTINATION_TOPIC "fleet/dhl/tracking-subscription/list/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/tracking/push/v1/subscriptions"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker"
            ADD "DHL-API-Key" "{value.json.api_key}"
    ADD EVENT DeleteTrackingSubscription
        WITH SOURCE_TOPIC "fleet/dhl/tracking-subscription/delete"
        WITH DESTINATION_TOPIC "fleet/dhl/tracking-subscription/delete/response"
        WITH METHOD "DELETE"
        WITH ENDPOINT "/tracking/push/v1/subscription/{value.json.id}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker"
            ADD "DHL-API-Key" "{value.json.api_key}"
            ADD "DHL-API-Hook-Secret" "{value.json.hook_secret}"
```

Deploy it with `-addConnector` (do not include `ADD METADATA`).

## Usage example

Call `TrackShipment` by publishing a JSON payload to its request topic, and read the reply on the response topic:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'fleet/dhl/shipment-tracking/get/response' &
mosquitto_pub -t 'fleet/dhl/shipment-tracking/get' -m '{"api_key": "<api_key>", "query": "<query>"}'
```

## Related

* [REST API Connectors](https://docs.coreflux.org/latest/connectors/rest-api/overview)
* [REST API Apps catalog](https://docs.coreflux.org/latest/connectors/rest-api-apps)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.