1. Go to this page and download the library: Download mvdnbrk/dhlparcel-php-api 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/ */
mvdnbrk / dhlparcel-php-api example snippets
$parcel = new \Mvdnbrk\DhlParcel\Resources\Parcel([
'reference' => 'your own reference for the parcel (optional)',
'recipient' => [
'first_name' => 'John',
'last_name' => 'Doe',
'street' => 'Poststraat',
'number' => '1',
'number_suffix' => 'A',
'postal_code' => '1234AA',
'city' => 'Amsterdam',
'cc' => 'NL',
],
'sender' => [
'company_name' => 'Your Company Name',
'street' => 'Pakketstraat',
'additional_address_line' => 'Industrie 9999',
'number' => '99',
'postal_code' => '9999AA',
'city' => 'Amsterdam',
'cc' => 'NL',
],
// Optional. This will be set as the default.
'pieces' => [
[
'parcel_type' => \Mvdnbrk\DhlParcel\Resources\Piece::PARCEL_TYPE_SMALL,
'quantity' => 1,
],
],
]);
php
$dhlparcel = new \Mvdnbrk\DhlParcel\Client();
$dhlparcel->setUserId('your-user-id');
$dhlparcel->setApiKey('your-api-key');
php
$shipment = $dhlparcel->shipments->create($parcel);
$shipment->id;
// For shipments with multiple pieces:
$shipment->pieces->each(function ($item) {
$item->label_id;
$item->barcode;
})
// For a shipment with one single piece:
$shipment->label_id;
$shipment->barcode;