# Создать товар

## Создание товара

### Описание

<mark style="color:green;">`POST`</mark> `https://api.lpmotor.ru/v1/shop/product`

#### Headers

| Name                                            | Type    | Description     |
| ----------------------------------------------- | ------- | --------------- |
| X-Api-User-Id<mark style="color:red;">\*</mark> | integer | ID пользователя |
| Authorization<mark style="color:red;">\*</mark> | string  | API токен       |

#### Request Body

| Name                                          | Type    | Description               |
| --------------------------------------------- | ------- | ------------------------- |
| short\_description                            | string  | короткое описание товара  |
| description                                   | string  | полное описание товара    |
| name<mark style="color:red;">\*</mark>        | string  | название товара           |
| sku                                           | string  | sku                       |
| site\_id<mark style="color:red;">\*</mark>    | integer | id сайта                  |
| description\_url                              | string  | ссылка на описание товара |
| price<mark style="color:red;">\*</mark>       | float   | цена                      |
| old\_price                                    | float   | предыдущая цена           |
| is\_visible<mark style="color:red;">\*</mark> | boolean | флаг видимости товара     |
| quantity                                      | integer | количество товара         |
| weight                                        | integer | вес                       |
| length                                        | integer | длина                     |
| width                                         | integer | ширина                    |
| height                                        | integer | высота                    |

{% tabs %}
{% tab title="201: Created " %}

```javascript
{
  "id": 0,
  "sku": "string",
  "name": "string",
  "description": "string",
  "price": 0,
  "is_visible": true,
  "quantity": 0,
  "weight": 0,
  "length": 0,
  "width": 0,
  "height": 0,
  "categories": [
    {
      "id": 0
    }
  ],
  "param_group_id": 0,
  "variants": [
    null
  ],
  "parent_id": 0,
  "old_price": 0,
  "short_description": "string",
  "description_url": "string",
  "image_list": [
    {
      "id": 0,
      "url": "string",
      "status_id": 0
    }
  ],
  "params": [
    {
      "id": 0,
      "type_id": 0,
      "name": "string",
      "unit": "string",
      "is_visible": true,
      "values": [
        {
          "id": 0,
          "label": "string",
          "value": "string",
          "is_visible": true,
          "image_status_id": 0,
          "image_url": "string"
        }
      ]
    }
  ],
  "modifiers": [
    {
      "id": 0,
      "type": 0,
      "name": "string",
      "price": "string",
      "max_count": 0,
      "default": true,
      "image": {
        "id": 0,
        "url": "string",
        "status_id": 0
      },
      "is_visible": true,
      "extra": [
        null
      ]
    }
  ]
}
```

{% endtab %}
{% endtabs %}

### Примеры

{% tabs %}
{% tab title="CURL" %}

```bash
curl \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "X-Api-User-Id: <<Your-user-id>>" \
-H "Authorization: Bearer <<Your-API-token>>" \
-X POST "https://api.lpmotor.ru/v1/shop/product" \
-d "{\"site_id\": 11111, \"name\": \"product name\", \"price\": 109.99, \"is_visible\": true}
```

{% endtab %}

{% tab title="PHP(CURL)" %}

```php
<?php
$ch = curl_init();
$url = 'https://api.lpmotor.ru/v1/shop/product';
$data = [
    'site_id'    => $siteId,
    'name'       => 'product name',
    'price'      => 109.99,
    'is_visible' => true,
];

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt(
    $ch,
    CURLOPT_HTTPHEADER,
    [
        'Host: api.lpmotor.ru',
        'X-Api-User-Id: ' . $userId,
        'Authorization: Bearer ' . $apiKey,
        'Content-Type: application/json',
        'Accept: application/json',
    ]
);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

$result = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$responseData = json_decode($result, true);

curl_close($ch);
```

{% endtab %}

{% tab title="PHP(Guzzle)" %}

```php
<?php
$client = new GuzzleHttp\Client([
    'base_uri' => 'https://api.lpmotor.ru',
    'headers'  => [
        'Content-Type'  => 'application/json',
        'Accept'        => 'application/json',
        'X-Api-User-Id' => $userId,
        'Authorization' => 'Bearer ' . $apiKey,
    ],
]);

$data = [
    'site_id'    => $siteId,
    'name'       => 'product name',
    'price'      => 109.99,
    'is_visible' => true,
];

$response = $client->post(
    '/v1/shop/product',
    [
        'json' => $data,
    ]
);
$statusCode = $response->getStatusCode();
$responseData = json_decode((string)$response->getBody(), true);
```

{% endtab %}

{% tab title="JavaScript(Axios)" %}

```javascript
http = Axios.create({
    baseURL: "https://api.lpmotor.ru",
    timeout: 30000,
    headers: {
        "Content-Type" : "application/json",
        "Accept"       : "application/json",
        "Cache-Control": "no-cache, no-store, must-revalidate",
        "X-Api-User-Id": userId,
        "Authorization": "Bearer " + myApiKey,
    }
});
http.post("/v1/shop/product", {
    site_id    : 11111,
    name       : "products name",
    price      : 109.99,
    is_visible : true,
})
.then(function (response) {
    console.log(response);
})
.catch(function (error) {
    console.log(error);
});
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.lpmotor.ru/tovary/sozdat-tovar.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
