PHP code example of phpsoftbox / wildberries

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

    

phpsoftbox / wildberries example snippets


use PhpSoftBox\Http\Message\RequestFactory;
use PhpSoftBox\Http\Message\StreamFactory;
use PhpSoftBox\Wildberries\WildberriesApiClient;

$client = new WildberriesApiClient(
    token: $_ENV['WILDBERRIES_API_TOKEN'],
    httpClient: $psr18Client,
    requestFactory: new RequestFactory(),
    streamFactory: new StreamFactory(),
    authorizationScheme: 'Bearer',
);

// Низкоуровневый вызов
$stocks = $client->marketplace()->get('/api/v3/orders/new');

// Вызов через секцию API
$parents = $client->products()->objectParentAll();

use PhpSoftBox\Wildberries\Retry\RateLimitRetryOptions;
use PhpSoftBox\Wildberries\Retry\WildberriesRetryEvent;
use PhpSoftBox\Wildberries\WildberriesApiClient;

$client = new WildberriesApiClient(
    token: $token,
    httpClient: $psr18Client,
    requestFactory: $requestFactory,
    streamFactory: $streamFactory,
    rateLimitRetry: new RateLimitRetryOptions(
        maxAttempts: 4,
        maxDelaySeconds: 30,
        maxTotalDelaySeconds: 60,
        onRetry: static function (WildberriesRetryEvent $event): void {
            // $event->attempt — номер предстоящей попытки: 2 для первого повтора.
            // Также доступны delaySeconds, method, endpoint и statusCode.
        },
    ),
);

use PhpSoftBox\Wildberries\WildberriesRateLimitException;

try {
    $result = $client->products()->tags();
} catch (WildberriesRateLimitException $exception) {
    $job->releaseAfter($exception->retryAfterSeconds());
}

use PhpSoftBox\Wildberries\Retry\CallbackRetryableRequestPolicy;
use PhpSoftBox\Wildberries\Retry\RateLimitRetryOptions;
use Psr\Http\Message\RequestInterface;

$retry = new RateLimitRetryOptions(
    requestPolicy: new CallbackRetryableRequestPolicy(
        static fn (RequestInterface $request): bool => $request->getUri()->getPath() !== '/custom/non-retryable',
    ),
);

$parents = $client->products()->objectParentAll()->makeDto();

$response = $client->marketplace()
    ->get('/api/v3/supplies/WB-123')
    ->makeDto();

use PhpSoftBox\Wildberries\WildberriesApiBasesEnum;

$client = new WildberriesApiClient(
    token: $testToken,
    httpClient: $psr18Client,
    requestFactory: new RequestFactory(),
    streamFactory: new StreamFactory(),
    authorizationScheme: 'Bearer',
    apiBases: WildberriesApiBasesEnum::sandbox(),
);

$client->sandbox()->fbsOrdersMake([
    'orders' => [
        ['sku' => 'BarcodeTest123', 'amount' => 1],
    ],
]);