PHP code example of picqer / sendcloud-php-client

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

    

picqer / sendcloud-php-client example snippets


$connection = new \Picqer\Carriers\SendCloud\Connection('apikey', 'apisecret');
$sendcloudClient = new \Picqer\Carriers\SendCloud\SendCloud($connection);

$parcels = $sendcloudClient->parcels()->all();

$parcel = $sendcloudClient->parcels()->find(2342);

$parcel = $sendcloudClient->parcels();

$parcel->shipment = 10; // Shipping method, get possibilities from $sendCloud->shippingMethods()->all()

$parcel->name = 'John Smith';
$parcel->company_name = 'ACME';
$parcel->address = 'Wellingtonstreet 25';
$parcel->city = 'Wellington';
$parcel->postal_code = '3423 DD';
$parcel->country = 'NL';
$parcel->order_number = 'ORDER2014-52321';

$parcel->requestShipment = true; // Specifically needed to create a shipment after adding the parcel

$parcel->save();

$labelUrl = $parcel->getPrimaryLabelUrl();

$documentDownloader = new \Picqer\Carriers\SendCloud\DocumentDownloader($connection);
$labelContents = $documentDownloader->getDocument($labelUrl, 'pdf');

try {
    $parcel->save();
} catch (SendCloudApiException $e) {
    throw new Exception($e->getMessage());
}

$parcel = $sendcloudClient->parcels();

$parcel->shipment = 9; // Shipping method, get possibilities from $sendCloud->shippingMethods()->all()

$parcel->name = 'John Smith';
$parcel->company_name = 'ACME';
$parcel->address = 'Wellingtonstreet 25';
$parcel->city = 'Wellington';
$parcel->postal_code = '3423 DD';
$parcel->country = 'CH';
$parcel->order_number = 'ORDER2014-52321';
$parcel->weight = 20.4;

// For international shipments
$parcel->customs_invoice_nr = 'ORD9923882';
$parcel->customs_shipment_type = 2; // Commercial goods
$parcel->parcel_items = [
    [
        'description' => 'Cork',
        'quantity' => 2,
        'weight' => 10.2,
        'value' => 12.93,
        'hs_code' => '992783',
        'origin_country' => 'CN',
    ]
];

$parcel->requestShipment = true; // Specifically needed to create a shipment after adding the parcel

$parcel->save();

composer