PHP code example of wishbox / cdek-library

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

    

wishbox / cdek-library example snippets




uzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory;
use WishboxCdek\CdekClient;
use WishboxCdek\Enum\OrderType;
use WishboxCdek\Request\Calculator\CalculateTariffRequest;
use WishboxCdek\Request\DeliveryPoint\GetDeliveryPointsRequest;
use WishboxCdek\Request\Intake\CreateIntakeRequest;
use WishboxCdek\Request\Location\GetCitiesRequest;
use WishboxCdek\Request\Location\GetRegionsRequest;
use WishboxCdek\Request\Order\CreateOrderRequest;
use WishboxCdek\Request\Order\OrderContact;
use WishboxCdek\Request\Order\OrderItemPayment;
use WishboxCdek\Request\Order\OrderLocation;
use WishboxCdek\Request\Order\OrderPackage;
use WishboxCdek\Request\Order\OrderPackageItem;
use WishboxCdek\Request\Order\OrderPhone;
use WishboxCdek\Request\Print\CreateOrdersPrintRequest;

$httpClient = new GuzzleClient();
$httpFactory = new HttpFactory();

$client = new CdekClient(
    $httpClient,
    $httpFactory,
    $httpFactory,
    [
        'base_url' => CdekClient::SANDBOX_BASE_URL,
        'account' => 'your-account',
        'password' => 'your-password',
    ]
);

$regions = $client->locations()->getRegions(new GetRegionsRequest(
    countryCodes: 'RU',
    size: 100,
));

$cities = $client->locations()->getCities(new GetCitiesRequest(
    countryCodes: 'RU',
    city: 'Moscow',
));

$deliveryPoints = $client->deliveryPoints()->getList(new GetDeliveryPointsRequest(
    cityCode: 44,
));

try {
    $order = $client->orders()->create(
        CreateOrderRequest::make(
            tariffCode: 139,
            sender: new OrderContact(
                name: 'Wishbox Sender',
                phones: [
                    new OrderPhone(number: '+79990000001'),
                ],
                contragentType: 'LEGAL_ENTITY',
            ),
            recipient: new OrderContact(
                name: 'John Doe',
                phones: [
                    new OrderPhone(number: '+79990000002'),
                ],
                email: '[email protected]',
            ),
            packages: [
                new OrderPackage(
                    number: 'PKG-1',
                    weight: 1000,
                    length: 10,
                    width: 10,
                    height: 10,
                    items: [
                        new OrderPackageItem(
                            name: 'Test item',
                            wareKey: 'SKU-1',
                            payment: new OrderItemPayment(value: 1000),
                            cost: 1000,
                            weight: 1000,
                            amount: 1,
                        ),
                    ],
                ),
            ],
        )
            ->withType(OrderType::INTERNET_SHOP)
            ->withFromLocation(new OrderLocation(code: 44, address: 'Sender street 1'))
            ->withToLocation(new OrderLocation(code: 137, address: 'Recipient street 10'))
            ->withNumber('ORDER-1')
            ->withComment('Created from Wishbox SDK')
    );

    $orderDetails = $client->orders()->getByUuid($order->entity?->uuid ?? '');

    $intake = $client->intakes()->create(new CreateIntakeRequest([
        'order_uuid' => $order->entity?->uuid,
        'intake_date' => '2026-03-30',
        'intake_time_from' => '10:00',
        'intake_time_to' => '14:00',
    ]));

    $print = $client->prints()->createOrders(new CreateOrdersPrintRequest([
        'orders' => [
            ['order_uuid' => $order->entity?->uuid],
        ],
        'copy_count' => 2,
    ]));

    echo $order->entity?->uuid;
    echo $orderDetails->entity?->uuid;
    echo $intake->entity?->uuid;
    echo $print->requests[0]->state;
} catch (\WishboxCdek\Exception\OrderValidationException $e) {
    foreach ($e->getErrors() as $error) {
        echo $error . PHP_EOL;
    }
} catch (\WishboxCdek\Exception\ApiResponseException $e) {
    foreach ($e->getErrors() as $error) {
        echo $error->code . ': ' . $error->message . PHP_EOL;
    }
}