PHP code example of trudslev / pakkelabels-php-sdk

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

    

trudslev / pakkelabels-php-sdk example snippets

5

    try {
		$label = new Pakkelabels('api_user', 'api_key');
    } catch (PakkelabelsException $e) {
      echo $e->getMessage();
    }
5

    echo $label->balance();
5

    $labels = $label->shipments(array('shipping_agent' => 'pdk', 'receiver_country' => 'DK'));
    print_r($labels);
5

    $base64 = $label->pdf(42);
    $pdf = base64_decode($base64);
    header('Content-type: application/pdf');
    header('Content-Disposition: inline; filename="label.pdf"');
    echo $pdf;
5

    $data = array(
      'shipping_agent' => 'pdk',
      'weight' => '1000',
      'receiver_name' => 'John Doe',
      'receiver_address1' => 'Some Street 42',
      'receiver_zipcode' => '5230',
      'receiver_city' => 'Odense M',
      'receiver_country' => 'DK',
      'sender_name' => 'John Wayne',
      'sender_address1' => 'The Batcave 1',
      'sender_zipcode' => '5000',
      'sender_city' => 'Odense C',
      'sender_country' => 'DK',
      'shipping_product_id' => '51',
      'services' => '11,12',
      'receiver_mobile' => '004560708090',
      'receiver_email' => '[email protected]',
      'test' => 'true' // Change to false when going live
    );

    $shipment = $label->create_shipment($data);
    echo 'Track&Trace: ' . $shipment['pkg_no'];
5

    $data = array(
      'country' => 'DK',
    );
    print_r($label->freight_rates($data));
5

    $data = array(
      'agent' => 'pdk',
      'zipcode' => '5240',
      'country' => 'DK',
    );
    print_r($label->pickup_points($data));