Ozon api php sdk

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

PHP client for Ozon Seller API

License

gam6itko/ozon-seller

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

composer require gam6itko/ozon-seller

Для взаимодействия библиотеки с Ozon-Api нужно дополнительно установить реализации PSR-18: HTTP Client и PSR-17: HTTP Factories.

composer require symfony/http-client composer require nyholm/psr7
use Gam6itko\OzonSeller\Service\V1\ProductService; use Symfony\Component\HttpClient\Psr18Client; $config = [$_SERVER['CLIENT_ID'], $_SERVER['API_KEY'], $_SERVER['API_URL']]; $client = new Psr18Client(); $svc = new ProductService($config, $client); //do stuff

Использование без Symfony

composer require php-http/guzzle6-adapter
use Gam6itko\OzonSeller\Service\V1\CategoriesService; use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle6\Client as GuzzleAdapter; use Http\Factory\Guzzle\RequestFactory; use Http\Factory\Guzzle\StreamFactory; $config = [ 'clientId' => '', 'apiKey' => '', 'host' => 'http://cb-api.ozonru.me/' ]; $client = new GuzzleAdapter(new GuzzleClient()); $requestFactory = new RequestFactory(); $streamFactory = new StreamFactory(); $svc = new CategoriesService($config, $client, $requestFactory, $streamFactory); //do stuff

Чтобы узнать какой класс и метод реализуют запрос на нужный URL воспользуйтесь скриптом bin/is_realized.php

php bin/is_realized.php | grep /v2/posting/fbs/get
/v2/posting/fbs/get: Gam6itko\OzonSeller\Service\V2\Posting\FbsService::get /v2/posting/fbs/get-by-barcode: NotRealized

Автор не всегда успевает добавлять реализации новых методов. Если нужного вам метода нет в библиотеке, то не стесняйтесь открыть issue или PR.

Читайте также:  Java windows path names

Больше примеров смотрите в папке tests/Service/

use Gam6itko\OzonSeller\Service\V1\CategoriesService; use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle6\Client as GuzzleAdapter; $config = [ 'clientId' => '', 'apiKey' => '', 'host' => 'http://cb-api.ozonru.me/' //sandbox ]; $adapter = new GuzzleAdapter(new GuzzleClient()); $svc = new CategoriesService($config, $adapter); //Server Response example: https://cb-api.ozonru.me/apiref/en/#t-title_categories $categoryTree = $svc->tree(); //Server Response example: https://cb-api.ozonru.me/apiref/en/#t-title_get_categories_attributes $attributes = $svc->attributes(17038826);
use Gam6itko\OzonSeller\Service\V2\Posting\CrossborderService; use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle6\Client as GuzzleAdapter; $config = [ 'clientId' => '', 'apiKey' => '', 'host' => 'http://cb-api.ozonru.me/' ]; $adapter = new GuzzleAdapter(new GuzzleClient()); $svc = new CrossborderService($config, $adapter); $postingNumber = '39268230-0002-3'; $orderArr = $svc->get($postingNumber); echo json_encode($orderArr);
< "result": [ < "address": < "address_tail": "г. Москва, ул. Центральная, 1", "addressee": "Петров Иван Владимирович", "city": "Москва", "comment": "", "country": "Россия", "district": "", "phone": "+7 495 123-45-67", "region": "Москва", "zip_code": "101000" >, "auto_cancel_date": "2019-11-18T11:30:11.571Z", "cancel_reason_id": 76, "created_at": "2019-11-18T11:30:11.571Z", "customer_email": "petrov@email.com", "customer_id": 60006, "in_process_at": "2019-11-18T11:30:11.571Z", "order_id": 77712345, "order_nr": "1111444", "posting_number": "39268230-0002-3", "products": [ < "name": "Фитнес-браслет", "offer_id": "DEP-1234", "price": "1900.00", "quantity": 1, "sku": 100056 > ], "shipping_provider_id": 0, "status": "awaiting_approve", "tracking_number": "" > ] >
use Gam6itko\OzonSeller\Service\V1\ProductService; use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle6\Client as GuzzleAdapter; $config = [ 'clientId' => '', 'apiKey' => '', // use prod host by default ]; $adapter = new GuzzleAdapter(new GuzzleClient()); $svcProduct = new ProductService($config, $adapter); $product = [ 'barcode' => '8801643566784', 'description' => 'Red Samsung Galaxy S9 with 512GB', 'category_id' => 17030819, 'name' => 'Samsung Galaxy S9', 'offer_id' => 'REDSGS9-512', 'price' => '79990', 'old_price' => '89990', 'premium_price' => '75555', 'vat' => '0', 'vendor' => 'Samsung', 'vendor_code' => 'SM-G960UZPAXAA', 'height' => 77, 'depth' => 11, 'width' => 120, 'dimension_unit' => 'mm', 'weight' => 120, 'weight_unit' => 'g', 'images' => [ [ 'file_name' => 'https://ozon-st.cdn.ngenix.net/multimedia/c1200/1022555115.jpg', 'default' => true, ], [ 'file_name' => 'https://ozon-st.cdn.ngenix.net/multimedia/c1200/1022555110.jpg', 'default' => false, ], [ 'file_name' => 'https://ozon-st.cdn.ngenix.net/multimedia/c1200/1022555111.jpg', 'default' => false, ], ], 'attributes' => [ [ 'id' => 8229, 'value' => '4747', ], [ 'id' => 9048, 'value' => 'Samsung Galaxy S9', ], [ 'id' => 4742, 'value' => '512 ГБ', ], [ 'id' => 4413, 'collection' => ['1', '2', '13'], ], [ 'id' => 4018, 'complex_collection' => [ [ 'collection' => [ [ 'id' => 4068, 'value' => 'Additional video', ], [ 'id' => 4074, 'value' => '5_-NKRVn7IQ', ], ], ], [ 'collection' => [ [ 'id' => 4068, 'value' => 'Another one video', ], [ 'id' => 4074, 'value' => '5_-NKRVn7IQ', ], ], ], ], ], ], ]; $svcProduct->import($product); // or $svcProduct->import([$product, $product1, $product2, ...]); // or $res = $svcProduct->import(['items' => [$product, $product1, $product2, ...] ]); echo $res['task_id']; // save it for checking by `importInfo`

About

PHP client for Ozon Seller API

Читайте также:  Audio player java example

Источник

Работа с Ozon Seller API в PHP

Примеры запросов к Seller API для добавление товаров, обновление остатков из PHP.

API ключи

Для доступа к API понадобится «Client Id» и «​API key», узнать их можно в настройках, в разделе «API ключи»:

Ozon Seller API

Создание или обновление товара

Документация Чтобы добавить товар нужно передать идентификатор категории озона, узнать их можно в xlsx-файле на странице https://seller.ozon.ru/app/products/import/file (кнопка «Скачать категории»). Так же по id категории загружаются характеристики и заполняются значениями. В каждой категории свой набор характеристик, некоторые из них обязательные для заполнения.

prepare("SELECT * FROM `prods` WHERE `ozon` = 1 LIMIT 100"); $sth->execute(); $prods = $sth->fetchAll(PDO::FETCH_ASSOC); if (!empty($prods)) < $items = array(); foreach ($prods as $prod) < // Получаем характеристики категории $data = array( 'attribute_type' =>'ALL', 'category_id' => array($prod['ozon_category']), 'language' => 'RU' ); $ch = curl_init("https://api-seller.ozon.ru/v3/category/attribute"); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Api-Key:' . $token, 'Client-Id:' . $client_id, 'Content-Type:application/json' )); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); $res = curl_exec($ch); curl_close($ch); // Заполнение характеристик $attributes = array(); $res = json_decode($res, true); foreach ($res['result'][0]['attributes'] as $attr) < // Бренд if ($prodres['name'] == 'Бренд') < $attributes[] = array( 'complex_id' =>0, 'id' => $attr['id'], 'values' => array( array( 'value' => $prod['name'] ) ) ); > // Описание товара if ($prodres['name'] == 'Аннотация') < $attributes[] = array( 'id' =>$attr['id'], 'values' => array( array( 'dictionary_value_id' => 0, 'value' => strip_tags($prod['text']) ) ) ); > if ($prodres['name'] == 'Артикул') < $attributes[] = array( 'id' =>$attr['id'], 'values' => array( array( 'dictionary_value_id' => 0, 'value' => $prod['sku'] ) ) ); > > $item = array( 'attributes' => $attributes, 'barcode' => $prod['barcode'], 'category_id' => $prod['ozon_category'], //'color_image' => '', //'complex_attributes' => array(), 'currency_code' => 'RUB', 'depth' => $prod['depth'], 'dimension_unit' => 'mm', 'height' => $prod['height'], 'images' => array( 'https://example.com/img/' . $prod['img_1'], 'https://example.com/img/' . $prod['img_2'], ), //'images360' => array(), 'name' => $prod['name'], 'offer_id' => $prod['id'], //'pdf_list' => array(), //'premium_pric' => '900', 'price' => $prod['price'], 'old_price' => $prod['price_old']; //'primary_image' => '', 'vat' => '0', 'weight' => $prod['weight'], 'weight_unit' => 'g', 'width' => $prod['width'] ); $items[] = $item; > $data = array( 'items' => $items ); $ch = curl_init('https://api-seller.ozon.ru/v2/product/import'); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Api-Key:' . $token, 'Client-Id:' . $client_id, 'Content-Type:application/json' )); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res, true); print_r($res); >

Ответ в случаи успеха:

Array ( [result] => Array( [task_id] => 123456789 ) )

Обновление цен

prepare("SELECT * FROM `prods` WHERE `ozon` = 1 LIMIT 100"); $sth->execute(); $prods = $sth->fetchAll(PDO::FETCH_ASSOC); if (!empty($prods)) < $items = array(); foreach ($prods as $prod) < $items[] = array( 'auto_action_enabled' =>'UNKNOWN', 'currency_code' => 'RUB', 'min_price' => '0', 'offer_id' => $prod['id'], 'old_price' => 0, 'price' => strval($prod['price']), ); > $data = array( 'prices' => $items ); $ch = curl_init('https://api-seller.ozon.ru/v1/product/import/prices'); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Api-Key:' . $token, 'Client-Id:' . $client_id, 'Content-Type:application/json' )); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res, true); print_r($res); >

Обновление остатков

prepare("SELECT * FROM `prods` WHERE `ozon` = 1 LIMIT 100"); $sth->execute(); $prods = $sth->fetchAll(PDO::FETCH_ASSOC); if (!empty($prods)) < $items = array(); foreach ($prods as $prod) < $items[] = array( 'offer_id' =>$prod['id'], 'stock' => $prod['count'], ); > $data = array( 'stocks' => $items ); $ch = curl_init('https://api-seller.ozon.ru/v1/product/import/stocks'); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Api-Key:' . $token, 'Client-Id:' . $client_id, 'Content-Type:application/json' )); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res, true); print_r($res); >

Источник

Оцените статью