Simple library to integrate application with DHL API
Important! This library isn’t complete. In this moment I implemented only few methods specified below.
composer install
<?php
require_once 'vendor/autoload.php';
$config = new \awaluk\DhlApi\Config(
'url to API',
'username',
'password'
);
$api = new \awaluk\DhlApi\Api($config);
Get API version
echo $api->getVersion();
Check delivery on Saturday for date and postal code
$saturdayDelivery = $api->getPostalCodeServices('00001', new DateTime('2017-09-02'))['deliverySaturday'];
Get shipments number for month
$shipments = $api->getMyShipments(new DateTime('2017-09-01'), new DateTime('2017-09-30'));
foreach ($shipments as $shipment) {
echo $shipment['shipmentId'];
}
Get waybill in PDF for shipment
$waybill = $api->getLabels('LP', 12345)['labelData'];
Errors handling with exceptions
try {
$saturdayDelivery = $api->getPostalCodeServices('00001', new DateTime('2017-09-02'))['deliverySaturday'];
} catch (\awaluk\DhlApi\Exception\ApiErrorException $e) {
echo $e->getMessage();
}