PHP code example of very-code-com / cargoboard-php
1. Go to this page and download the library: Download very-code-com/cargoboard-php 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/ */
very-code-com / cargoboard-php example snippets
use VeryCodeCom\Cargoboard\CargoboardClient;
use VeryCodeCom\Cargoboard\Dto\{Address, Consignee, Line, ShipmentRequest, Shipper};
use VeryCodeCom\Cargoboard\Enum\{CountryCode, PackageType, Product};
$client = CargoboardClient::sandbox('your-api-key');
$request = new ShipmentRequest(
product: Product::Standard,
shipper: new Shipper(
address: new Address('40239', CountryCode::DE, 'Düsseldorf', 'Examplestreet 12a'),
name: 'Producer ABC GmbH & Co. KG',
pickupOn: '2026-08-20',
),
consignee: new Consignee(
address: new Address('41061', CountryCode::DE, 'Mönchengladbach', 'Examplestreet 5'),
name: 'Consignee ABC AG',
),
// Dimensions in centimetres, weight in kilograms, both PER UNIT.
lines: [new Line('Werkzeugmaschine', 1, PackageType::EuroPallet, 120, 80, 120, 200.0)],
);
// 1. Get a binding price.
$quotation = $client->quote($request);
echo $quotation->price; // 90.85 EUR
echo $quotation->runtime; // 1-2 days
// 2. Book that exact price.
$order = $client->bookQuotation($quotation->id, $request);
echo $order->reference; // 10374504 <- the shipment number
// 3. Get the labels.
file_put_contents('labels.pdf', $client->fetchLabels($order->id));
// Named constructors
$client = CargoboardClient::sandbox($apiKey);
$client = CargoboardClient::production($apiKey);
// From environment variables (recommended)
$client = new CargoboardClient(CargoboardConfig::fromEnv());
// From array (framework config)
$config = CargoboardConfig::fromArray([
'api_key' => '...', 'env' => 'sandbox', 'timeout' => 30,
]);