Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit ddb6dbc

Browse files
committed
initial commit
0 parents  commit ddb6dbc

7 files changed

Lines changed: 981 additions & 0 deletions

File tree

LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
The BSD 3-Clause License
2+
3+
Copyright (c) 2022 Leonid Sheikman (leonid74) All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification,
6+
are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its contributors
16+
may be used to endorse or promote products derived from this software
17+
without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28+
OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# (English) Wildberries REST API statistics client library with throttling requests
2+
## Русское описание ниже
3+
4+
A simple Wildberries REST API statistics client library with throttling requests (for example, no more than 10 requests per second according to API rules) and an example for PHP.
5+
6+
Statistics API Documentation [Wildberries REST API statistics Documentation](https://images.wbstatic.net/portal/education/Kak_rabotat'_s_servisom_statistiki.pdf)
7+
New API Documentation [Wildberries REST API Documentation](https://suppliers-api.wildberries.ru/swagger/index.html)
8+
9+
### Installing
10+
11+
Via Composer:
12+
13+
```bash
14+
composer require Leonid74/wildberries-api-php
15+
```
16+
17+
### Usage
18+
19+
```php
20+
<?php
21+
require 'vendor/autoload.php';
22+
23+
// Without Composer (and instead of "require 'vendor/autoload.php'"):
24+
// require("your-path/wildberries-api-php/src/WbApiInterface.php");
25+
// require("your-path/wildberries-api-php/src/WbApiClient.php");
26+
27+
use Leonid74\Wildberries\WbApiClient;
28+
29+
require_once 'vendor/autoload.php';
30+
31+
$token = '<you token x64>';
32+
$dateFrom = '01-01-2022';
33+
$dateTo = '19-01-2022';
34+
35+
try {
36+
// Create new client
37+
$WbApiClient = new WbApiClient( $token );
38+
39+
// DEBUG level can be one of: DEBUG_NONE (default) or DEBUG_URL, DEBUG_HEADERS, DEBUG_CONTENT
40+
// no debug
41+
// $WbApiClient->debugLevel = WbApiClient::DEBUG_NONE;
42+
// only URL level debug
43+
// $WbApiClient->debugLevel = WbApiClient::DEBUG_URL;
44+
// only HEADERS level debug
45+
// $WbApiClient->debugLevel = WbApiClient::DEBUG_HEADERS;
46+
// max level of debug messages to STDOUT
47+
// $WbApiClient->debugLevel = WbApiClient::DEBUG_CONTENT;
48+
$WbApiClient->debugLevel = WbApiClient::DEBUG_URL;
49+
50+
// set the trottling of HTTP requests to 2 per second
51+
$WbApiClient->throttle = 2;
52+
} catch ( Exception $e ) {
53+
die( "Critical exception when creating ApiClient: ({$e->getCode()}) " . $e->getMessage() );
54+
}
55+
56+
/*
57+
* Example: Get the sales
58+
*/
59+
$sales = $WbApiClient->sales( $dateFrom );
60+
if ( isset( $sales->is_error ) ) {
61+
echo "\nError: " . implode( '; ', $sales->errors );
62+
} else {
63+
var_dump( $sales );
64+
}
65+
66+
/*
67+
* Example: Get the report detail by period
68+
*/
69+
$reportDetailByPeriod = $WbApiClient->reportDetailByPeriod( $dateFrom, $dateTo );
70+
if ( isset( $reportDetailByPeriod->is_error ) ) {
71+
echo "\nError: " . implode( '; ', $reportDetailByPeriod->errors );
72+
} else {
73+
var_dump( $reportDetailByPeriod );
74+
}
75+
76+
// You can set a common date (dateFrom) via the setDateFrom() function and then access other functions without passing the date
77+
$WbApiClient->setDateFrom( $dateFrom );
78+
$sales = $WbApiClient->sales();
79+
$incomes = $WbApiClient->incomes();
80+
81+
```
82+
83+
# (Russian) Клиентская REST API библиотека статистики Wildberries с регулированием запросов
84+
85+
Простая клиентская REST API библиотека статистики Wildberries с регулированием запросов (например, не более 10 запросов в секунду в соответствии с правилами API) и примером для PHP.
86+
87+
Описание API [Wildberries REST API statistics](https://images.wbstatic.net/portal/education/Kak_rabotat'_s_servisom_statistiki.pdf)
88+
Описание нового API [Wildberries REST API](https://suppliers-api.wildberries.ru/swagger/index.html)
89+
90+
### Установка
91+
92+
Через Composer:
93+
94+
```bash
95+
composer require Leonid74/wildberries-api-php
96+
```
97+
98+
### Использование
99+
100+
```php
101+
<?php
102+
require 'vendor/autoload.php';
103+
104+
// Без Composer можно подключить вот так (вместо "require 'vendor/autoload.php'"):
105+
// require("your-path/wildberries-api-php/src/WbApiInterface.php");
106+
// require("your-path/wildberries-api-php/src/WbApiClient.php");
107+
108+
use Leonid74\Wildberries\WbApiClient;
109+
110+
require_once 'vendor/autoload.php';
111+
112+
$token = '<Ваш токен партнера x64>';
113+
$dateFrom = '01-01-2022';
114+
$dateTo = '19-01-2022';
115+
116+
try {
117+
// Создаем новый клиент
118+
$WbApiClient = new WbApiClient( $token );
119+
120+
// Уровень DEBUG может быть одним из: DEBUG_NONE (по умолчанию) или DEBUG_URL, DEBUG_HEADERS, DEBUG_CONTENT
121+
// без вывода отладочной информации
122+
// $WbApiClient->debugLevel = WbApiClient::DEBUG_NONE;
123+
// выводим только URL запросов/ответов
124+
// $WbApiClient->debugLevel = WbApiClient::DEBUG_URL;
125+
// выводим только URL и заголовки запросов/ответов
126+
// $WbApiClient->debugLevel = WbApiClient::DEBUG_HEADERS;
127+
// выводим URL, заголовки и всю остальную информацию запросов/ответов в STDOUT
128+
// $WbApiClient->debugLevel = WbApiClient::DEBUG_CONTENT;
129+
$WbApiClient->debugLevel = WbApiClient::DEBUG_URL;
130+
131+
// Устанавливаем троттлинг в 2 запроса в секунду
132+
$WbApiClient->throttle = 2;
133+
} catch ( Exception $e ) {
134+
die( "Критическая ошибка при создании ApiClient: ({$e->getCode()}) " . $e->getMessage() );
135+
}
136+
137+
/*
138+
* Пример: Получаем продажи
139+
*/
140+
$sales = $WbApiClient->sales( $dateFrom );
141+
if ( isset( $sales->is_error ) ) {
142+
echo "\nError: " . implode( '; ', $sales->errors );
143+
} else {
144+
var_dump( $sales );
145+
}
146+
147+
/*
148+
* Пример: Получаем отчет о продажах по реализации
149+
*/
150+
$reportDetailByPeriod = $WbApiClient->reportDetailByPeriod( $dateFrom, $dateTo );
151+
if ( isset( $reportDetailByPeriod->is_error ) ) {
152+
echo "\nError: " . implode( '; ', $reportDetailByPeriod->errors );
153+
} else {
154+
var_dump( $reportDetailByPeriod );
155+
}
156+
157+
// Можно задать общую дату (dateFrom) через функцию setDateFrom() и затем обращаться к другим функциям, не передавая дату
158+
$WbApiClient->setDateFrom( $dateFrom );
159+
$sales = $WbApiClient->sales();
160+
$incomes = $WbApiClient->incomes();
161+
162+
```

composer.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "leonid74/wildberries-api-php",
3+
"type": "library",
4+
"description": "Wildberries REST API statistics client library with throttling requests",
5+
"keywords": [
6+
"Wildberries",
7+
"WB",
8+
"rest",
9+
"api",
10+
"sdk",
11+
"client",
12+
"stat",
13+
"statistics"
14+
],
15+
"homepage": "https://github.com/leonid74/wildberries-api-php",
16+
"license": "BSD-3-Clause",
17+
"authors": [
18+
{
19+
"name": "leonid74",
20+
"homepage": "https://github.com/leonid74/",
21+
"role": "Developer"
22+
}
23+
],
24+
"require": {
25+
"php": ">=7.4",
26+
"ext-curl": "*",
27+
"ext-json": "*",
28+
"josantonius/httpstatuscode": "^1.1"
29+
},
30+
"require-dev": {
31+
"automattic/phpcs-neutron-standard": "^1.7",
32+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
33+
"phpunit/phpunit": "^9",
34+
"squizlabs/php_codesniffer": "^3.5"
35+
},
36+
"autoload": {
37+
"psr-4": {
38+
"Leonid74\\Wildberries\\": "src/"
39+
}
40+
},
41+
"scripts": {
42+
"post-update-cmd": [
43+
"@composer dump-autoload"
44+
],
45+
"check-code": [
46+
"phpcs -sp src/ tests/"
47+
],
48+
"tests": [
49+
"@php vendor/bin/phpunit tests"
50+
]
51+
},
52+
"config": {
53+
"process-timeout": 0,
54+
"sort-packages": true,
55+
"optimize-autoloader": true
56+
}
57+
}

example/index.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/**
4+
* Wildberries REST API Client Usage Example
5+
*
6+
* @see Wildberries REST API statistics Documentation
7+
* (https://images.wbstatic.net/portal/education/Kak_rabotat'_s_servisom_statistiki.pdf)
8+
* @see Wildberries REST API Documentation
9+
* (https://suppliers-api.wildberries.ru/swagger/index.html)
10+
*
11+
* @author Leonid74 leonid@sheikman.ru
12+
*/
13+
14+
use Leonid74\Wildberries\WbApiClient;
15+
16+
require_once 'vendor/autoload.php';
17+
18+
$token = '<you token x64>';
19+
$dateFrom = '01-01-2022';
20+
$dateTo = '19-01-2022';
21+
22+
try {
23+
$WbApiClient = new WbApiClient( $token );
24+
$WbApiClient->debugLevel = WbApiClient::DEBUG_URL;
25+
$WbApiClient->throttle = 2;
26+
} catch ( Exception $e ) {
27+
die( "Критическая ошибка при создании ApiClient: ({$e->getCode()}) " . $e->getMessage() );
28+
}
29+
30+
$sales = $WbApiClient->sales( $dateFrom );
31+
if ( isset( $sales->is_error ) ) {
32+
echo "\nError: " . implode( '; ', $sales->errors );
33+
} else {
34+
var_dump( $sales );
35+
}
36+
37+
$reportDetailByPeriod = $WbApiClient->reportDetailByPeriod( $dateFrom, $dateTo );
38+
if ( isset( $reportDetailByPeriod->is_error ) ) {
39+
echo "\nError: " . implode( '; ', $reportDetailByPeriod->errors );
40+
} else {
41+
var_dump( $reportDetailByPeriod );
42+
}
43+
44+
// You can set a common date (dateFrom) via the setDateFrom() function and then access other functions without passing the date
45+
// Можно задать общую дату (dateFrom) через функцию setDateFrom() и затем обращаться к другим функциям, не передавая дату
46+
$WbApiClient->setDateFrom( $dateFrom );
47+
$sales = $WbApiClient->sales();
48+
$incomes = $WbApiClient->incomes();

0 commit comments

Comments
 (0)