Rus
Eng
Работа с API OZONE
Order site
By contacting me you will receive a reliable and knowledgeable contractor who will quickly and efficiently implement any task for you and your business.

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

Please message me to discuss the task. I work remotely and officially (as a self-employed professional); my hourly rate is 1,800 RUB, and I can dedicate 3–4 hours a day to the project. I respond quickly, and the consultation is free.

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