Working with API OZONE
Rus
Eng
Работа с API OZONE

All English-language materials have been translated fully automatically using the Google service

Get the rest of all products in the store on Ozone via API

function getProductBalance($page = 1){
    $url = 'http://api-seller.ozon.ru/v1/product/info/stocks';

    $headers = [
        'Content-Type: application/json',
        'Host: api-seller.ozon.ru',
        'Client-Id: ' . $CLIENT_ID,
        'Api-Key: ' . $API_CODE
    ];

    $data = [
        'page' => $page,
        'page_size' => '1000',
    ];

    $options = [
        CURLOPT_URL => $url,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POSTFIELDS => json_encode($data),
        CURLOPT_HTTPHEADER => $headers
    ];

    $ch = curl_init();

    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);

    //std to array
    return json_decode(json_encode(json_decode($result)), True);
}

$result = getProductBalance();

// Calculate the number of goods received on the first request
$number = count($result['result']['items']);
// Get the total number of products
$total = $result['result']['total'];
// Calculate the number of requests required to get the total number with the current step
$pages = ceil($total / $number);
// Initiate a temporary variable where we will add newly received products
$items = $result['result']['items'];

for($i = 2; $i < $pages + 1; ++$i) {
    $result = getProductBalance($i);
    $items = array_merge($items,$result['result']['items']);
}

$result = [];

foreach ($items as $k => $v){
    $result[$v['offer_id']] = $v;
}

Get information from Ozone about one product by its id

function getStockById($data){
    $url = 'http://api-seller.ozon.ru/v2/product/info';

    $headers = [
        'Content-Type: application/json',
        'Host: api-seller.ozon.ru',
        'Client-Id: ' . $CLIENT_ID,
        'Api-Key: ' . $API_CODE
    ];

    $options = [
        CURLOPT_URL => $url,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POSTFIELDS => json_encode($data),
        CURLOPT_HTTPHEADER => $headers
    ];

    $ch = curl_init();

    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);

    //std to array
    return json_decode(json_encode(json_decode($result)), True);
}

// Usage
$IDS = [
    'offer_id' => '52523',
];

$product = getStockById($IDS);

We receive information about specific products (together with leftovers) by their id

function getStocksById($data){
    $url = 'http://api-seller.ozon.ru/v2/product/info/list';

    $headers = [
        'Content-Type: application/json',
        'Host: api-seller.ozon.ru',
        'Client-Id: ' . $CLIENT_ID,
        'Api-Key: ' . $API_CODE
    ];

    $options = [
        CURLOPT_URL => $url,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POSTFIELDS => json_encode($data),
        CURLOPT_HTTPHEADER => $headers
    ];

    $ch = curl_init();

    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);

    //std to array
    return json_decode(json_encode(json_decode($result)), True);
}

// Использование
$IDS = [
    'offer_id' => ['77777', '55555'],
    'product_id' => [],
    'sku' => [],
];

$products = getStocksById($IDS);

Comments

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Are you developing a new service, making improvements to the existing one and want to be better than your competitors? You have come to the right place. I offer you a comprehensive studio-level website development. From me you can order design, layout, programming, development of non-traditional functionality, implementation of communication between CMS, CRM and Data Analitics, as well as everything else related to sites, except for promotion.

Contact, I will always advise on all questions and help you find the most effective solution for your business. I am engaged in the creation of sites in Novosibirsk and in other regions of Russia, I also work with the CIS countries. You will be satisfied with our cooperation

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site

Contact with me
Send message
By submitting the form, you automatically confirm that you have read and accept Privacy policy of site
Sending successful!
Thank you for contacting :) I will contact you as soon as possible
Sending failed
An error occurred while sending the request. Please wait and try again after a while or call my phone number