> For the complete documentation index, see [llms.txt](https://developer.lpmotor.ru/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.lpmotor.ru/tovary/import.md).

# Импорт

## Импорт товаров

### Описание

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

#### Headers

| Name                                            | Type    | Description |
| ----------------------------------------------- | ------- | ----------- |
| Authorization<mark style="color:red;">\*</mark> | string  |             |
| X-Api-User-Id<mark style="color:red;">\*</mark> | integer |             |

#### Request Body

| Name                                         | Type    | Description                                            |
| -------------------------------------------- | ------- | ------------------------------------------------------ |
| site\_id<mark style="color:red;">\*</mark>   | integer | ID сайта                                               |
| data\_file<mark style="color:red;">\*</mark> | string  | Контент файла. Данные должны быть кодированы в base64. |
| file\_type<mark style="color:red;">\*</mark> | String  | Тип файла. Поддерживаемые значения: **csv, yml**       |

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

```javascript
{
  "job_id": 0
}
```

{% endtab %}
{% endtabs %}

### Примеры

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

```bash
export products_csv=$(cat products.csv | base64)
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/import" \ 
-d "{\"data_file\": \"${products_csv}\",\"site_id\":11111,\"file_type\":\"csv\"}"
```

{% endtab %}

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

```php
<?php

$data = [
    'site_id': 11111,
    'file_type': "csv",
    'data_file': base64_encode(file_get_contents('products.csv')),
];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.lpmotor.ru/v1/shop/product/import');
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);
```

{% 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,
    ],
]);
$response = $client->post(
    '/v1/shop/product/import',
    [
        'json' => [
            'data_file' => base64_encode(file_get_contents('products.csv')),
            'site_id' => $siteId,
            'file_type' => 'csv',
        ],
    ]
);
$statusCode = $response->getStatusCode();
```

{% endtab %}
{% endtabs %}
