PHP code example of smart-dato / dhl-connect-plus-sdk

1. Go to this page and download the library: Download smart-dato/dhl-connect-plus-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

smart-dato / dhl-connect-plus-sdk example snippets


return [
    'url' => env('DHL_CONNECT_PLUS_SDK_BASE_URL', 'https://external.dhl.es/cimapi/api/v1/customer'),
    'auth' => [
        'username' => env('DHL_CONNECT_PLUS_SDK_USERNAME', 'Username2025'),
        'password' => env('DHL_CONNECT_PLUS_SDK_PASSWORD', 'Password312'),
        'customer_id' => env('DHL_CONNECT_PLUS_SDK_CUSTOMER_ID', '00-111000'),
    ],
];

use SmartDato\DhlConnectPlusClient\DhlConnectPlusConnector;
use SmartDato\DhlConnectPlusClient\Requests\Authentication\Authenticate;

$connector = new DhlConnectPlusConnector;
$token = $connector->send(new Authenticate('test', 'user'));
// Token is automatically stored and used for subsequent requests

use SmartDato\DhlConnectPlusClient\DhlConnectPlusConnector;
use SmartDato\DhlConnectPlusClient\Dto\Input\Shipment\CreateShipmentPayload;
use SmartDato\DhlConnectPlusClient\Dto\Input\Shipment\Receiver;
use SmartDato\DhlConnectPlusClient\Dto\Input\Shipment\Sender;
use SmartDato\DhlConnectPlusClient\Requests\Shipment\Create;

$payload = new CreateShipmentPayload(
    quantity: 2,
    weight: 5,
    incoterms: 'CPT',
    receiver: new Receiver(
        name: 'DHL Parcel Madrid',
        address: 'Río Almanzora,s/n',
        city: 'Getafe',
        postalcode: '28906',
        country: 'ES',
        phone: '+34935656885',
        email: '[email protected]'
    ),
    sender: new Sender(
        name: 'DHL Parcel Barcelona',
        address: 'Les Minetes,2-3',
        city: 'Santa Perpetua',
        postalcode: '08130',
        country: 'ES',
        phone: '+34935656885',
        email: '[email protected]'
    ),
    reference: 'ALB123456',
    weightVolume: 0,
    codAmount: 0,
    codExpenses: 'P',
    codCurrency: 'EUR',
    insuranceAmount: 0,
    insuranceExpenses: 'P',
    insuranceCurrency: 'EUR',
    deliveryNote: 'S',
    remarks1: '',
    remarks2: '',
    contactName: '',
    goodsDescription: '',
    customsValue: 0,
    customsCurrency: '',
    format: 'PDF'
);

$connector = new DhlConnectPlusConnector;
$label = $connector->send(new Create($payload));

// Access tracking number and label
$trackingNumber = $label->tracking;
$labelBase64 = $label->label;

use SmartDato\DhlConnectPlusClient\DhlConnectPlusConnector;
use SmartDato\DhlConnectPlusClient\Requests\Tracking\Track;
use SmartDato\DhlConnectPlusClient\Enums\Idioma;
use SmartDato\DhlConnectPlusClient\Enums\Show;


$connector = new DhlConnectPlusConnector;
$trackEvent = $connector->send(new Track(
    id: '0870002260',
    idioma: Idioma::En,
    show: Show::Events,
));
// Returns array of tracking events
bash
php artisan vendor:publish --tag="dhl-connect-plus-sdk-config"