PHP code example of dhl-plugins / dhl-api-wrapper

1. Go to this page and download the library: Download dhl-plugins/dhl-api-wrapper 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/ */

    

dhl-plugins / dhl-api-wrapper example snippets




$client = new \Dhl\ApiClient([
    'apiUser' => $apiUser,
    'apiKey' => $apiKey,
    'accountId' => $accountId,
    'organisationId' => $organisationId,
]);

// Create a DHL shipping label
$label = $client->createLabel($parameters);
$rawPdf = $labelResult->offsetGet('pdf');
if (!file_put_contents('DHLshippingLabel.pdf', base64_decode($rawPdf))) {
    printf('could not write label.%s', PHP_EOL);
} else {
    printf('Shipping label writen.%s', PHP_EOL);
}

// Retrieve the capabilities for your account and shipment information.
// The result can be used as `options` in the createLabel call.
$result = $client->capabilities([
    'fromCountry' => 'NL',
    'fromPostalCode' => '3542 AD',
    'toCountry' => 'NL',
    'toPostalCode' => '3542 AB',
]);
printf('<pre>%s</pre>', print_r($result, true));

// Get a list of all destination Countries.
$result = $client->destinationCountries(['senderType' => 'business', 'fromCountry' => 'NL']);
printf('<pre>%s</pre>', print_r($result, true));
bash
# Install Composer
curl -sS https://getcomposer.org/installer | php