PHP code example of datalinx / dpd-php-sdk

1. Go to this page and download the library: Download datalinx/dpd-php-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/ */

    

datalinx / dpd-php-sdk example snippets


// Set up the API
$dpd = new \DataLinx\DPD\API(getenv('DPD_USERNAME'), getenv('DPD_PASSWORD'), getenv('DPD_COUNTRY_CODE'));

// Prepare the request
$request = new \DataLinx\DPD\Requests\ParcelImport($dpd);
$request->name1 = 'Zdravko Dren';
$request->street = 'Partizanska';
$request->rPropNum = '44';
$request->city = 'Izola';
$request->country = 'SI';
$request->pcode = '6310';
$request->num_of_parcel = 1;
$request->parcel_type = ParcelType::CLASSIC_COD;
$request->cod_amount = 1234.56;
$request->cod_purpose = 'CODREF001';
$request->predict = true;

try {
    $response = $request->send();
    
    // Get parcel numbers
    $parcel_no = $response->getParcelNumbers();
    
    // $parcel_no is now an array with parcel numbers, e.g. ["16962023438943"]

} catch (\DataLinx\DPD\Exceptions\ValidationException $exception) {
    // Handle request validation exception
} catch (\DataLinx\DPD\Exceptions\APIException $exception) {
    // Handle API exception
} catch (\Exception $exception) {
    // Handle other exceptions
}
shell
composer