Answer the question
In order to leave comments, you need to log in
How to add products to ozon via its API?
Hello!
I'm trying to add products to Ozon via API using PHP guzzle http.
Here is my class code for working with the Ozon API:
namespace App\Models\Services;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
class ApiOzon
{
protected $client;
/**
* ApiOzon constructor.
*/
public function __construct()
{
$this->client = new Client([
'headers' => [
'Client-Id' => config('app.ozon.client-id'),
'Api-Key' => config('app.ozon.api-key'),
'Content-Type' => 'application/json'
],
'base_uri' => config('app.ozon.base_uri')
]);
}
/**
* Add products
*
* @param array $items
* @return array|mixed
*/
public function addProducts(array $items)
{
try {
$response = $this->client
->post('/v2/product/import', $items)->getBody()->getContents();
} catch (GuzzleException $e) {
return ['error' => $e->getMessage()];
}
return json_decode($response, true);
}
}
public function testAddProducts()
{
$items = [
'items' => [
[
'attributes' => [
[
'id' => 0,
]
],
'category_id' => 0,
'depth' => 200,
'dimension_unit' => 'mm',
'height' => 200,
'images' => ['string'],
'offer_id' => 0,
'price' => '100',
'vat' => 0,
'weight' => 1,
'weight_unit' => 'kg',
'width' => 200,
],
],
];
$client = new ApiOzon();
$response = $client->addProducts($items);
dd($response);
}
array:1 [
"error" => """
Client error: `POST http://cb-api.ozonru.me/v2/product/import` resulted in a `400 Bad Request` response:\n
{"error":{"code":"BAD_REQUEST","message":"Invalid JSON payload","data":[{"name":"cause","code":"","value":"EOF","message (truncated...)\n
"""
]
Answer the question
In order to leave comments, you need to log in
Invalid JSON payload
We are also going to start working with Ozon.
We decided to use a ready-made solution:
we already have XML2Ozon XML in the YML format.
Perhaps useful.
Сервис Tovaroved.net берёт интеграцию на себя. От продавца нужен только YML-фид с данными.
Для новых продавцов - бесплатно!
Это возможно за счет статуса сертифицированного технологического партнёра Ozon.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question