PHP code example of leonid74 / wildberries-api-php
1. Go to this page and download the library: Download leonid74/wildberries-api-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/ */
leonid74 / wildberries-api-php example snippets
ithout Composer (and instead of "php/src/WbApiInterface.php");
// hp';
$token = '<you token x64>';
$dateFrom = '01-01-2022';
$dateTo = '19-01-2022';
try {
// Create new client
$WbApiClient = new WbApiClient( $token );
// DEBUG level can be one of: DEBUG_NONE (default) or DEBUG_URL, DEBUG_HEADERS, DEBUG_CONTENT
// no debug
// $WbApiClient->debugLevel = WbApiClient::DEBUG_NONE;
// only URL level debug
// $WbApiClient->debugLevel = WbApiClient::DEBUG_URL;
// only URL and HEADERS level debug
// $WbApiClient->debugLevel = WbApiClient::DEBUG_HEADERS;
// max level of debug messages to STDOUT
// $WbApiClient->debugLevel = WbApiClient::DEBUG_CONTENT;
$WbApiClient->debugLevel = WbApiClient::DEBUG_URL;
// set the trottling of HTTP requests to 2 per second
$WbApiClient->throttle = 2;
} catch ( Exception $e ) {
die( "Critical exception when creating ApiClient: ({$e->getCode()}) " . $e->getMessage() );
}
/*
* Example: Get the sales
*/
$sales = $WbApiClient->sales( $dateFrom );
if ( isset( $sales->is_error ) ) {
echo "\nError: " . implode( '; ', $sales->errors );
} else {
var_dump( $sales );
}
/*
* Example: Get the report detail by period
*/
$reportDetailByPeriod = $WbApiClient->reportDetailByPeriod( $dateFrom, $dateTo );
if ( isset( $reportDetailByPeriod->is_error ) ) {
echo "\nError: " . implode( '; ', $reportDetailByPeriod->errors );
} else {
var_dump( $reportDetailByPeriod );
}
// You can set a common date (dateFrom) via the setDateFrom() function and then access other functions
// without passing the date
$WbApiClient->setDateFrom( $dateFrom );
$sales = $WbApiClient->sales();
$incomes = $WbApiClient->incomes();
bash
composer
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.