# Работа с заявками

## Работа с заявками из корзины

## Список заявок

<mark style="color:blue;">`GET`</mark> `https://api.lpmotor.ru/v1/lead`

Получение списка заявок по фильтрам

#### Query Parameters

| Name             | Type   | Description                                                                                         |
| ---------------- | ------ | --------------------------------------------------------------------------------------------------- |
| offset           | string | С какого по счету элемента выдавать список. По умолчанию - 0                                        |
| limit            | string | Лимит выдаваемых сайтов. По умолчанию - 18                                                          |
| sort\_field      | string | Тип сортировки поля. По умолчанию - id                                                              |
| sort\_dir        | string | Сортировка по возрастанию или убыванию. Доступные значения - DESC,ASC. По умолчанию - DESC          |
| type\_id         | array  | Выбор типа заявки для показа. Список типов в таблице. По умолчанию показываются все типы            |
| status\_id       | array  | Статус заявки. Список статусов в таблице ниже. По умолчанию показываются заявки со всеми статусами. |
| page\_id         | string | ID страницы                                                                                         |
| site\_id         | string | ID сайта                                                                                            |
| d\_create\_start | string | Время создания заявки в формате  ISO8601.                                                           |
| d\_create\_end   | string | Время создания заявки в формате ISO8601.                                                            |
| search\_text     | string | Произвольный текст. ищет совпадения в имени, email и номере телефоне.                               |

#### Headers

| Name          | Type    | Description     |
| ------------- | ------- | --------------- |
| X-Api-User-Id | integer | ID пользователя |
| Authorization | string  | API-токен       |

{% tabs %}
{% tab title="200 Cake successfully retrieved." %}

```
{
  "count": 0,
  "sum": 0,
  "limit": 0,
  "offset": 0,
  "leads": [
    {
      "id": 0,
      "page_id": 0,
      "name": "string",
      "phone": "string",
      "email": "string",
      "ip": "string",
      "ip_banned": 0,
      "is_del": 0,
      "type_id": 0,
      "status_id": 0,
      "f_expense": 0,
      "f_profit": 0,
      "kanban_position": 0,
      "d_created": "string",
      "page": {
        "id": 0,
        "user_id": 0,
        "name": "string",
        "url": "string",
        "site_id": 0,
        "is_enabled": true,
        "d_last_change": "string",
        "site": {
          "id": int,
          "title": "string",
          "subdomain": "string",
          "attached_domain": "string",
          "is_del": false
        },
        "is_base_variant": false,
        "is_variant": false,
        "variant_name": "string"
      },
      "cart": null,
      "total_price": 0
    }
  ]
}
```

{% 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 GET "https://api.lpmotor.ru/v1/lead?d_create_start=2020-08-09+00:00:00%2B05:00&sort_field[]=dCreated&sort_dir[]=ASC&status_id[]=1&limit=18&offset=0"
```

{% endtab %}

{% tab title="PHP CURL" %}

```php
<?php
$ch = curl_init();
$url = 'https://api.lpmotor.ru/v1/lead';
$params = [
    'd_create_start' => '2021-02-16T09:25:43+00:00',
    'd_create_end' => '2021-03-16T09:25:43+00:00',
    'status_id' => [1],
    'type_id' => [1],
];
$url .= '?' . http_build_query($params);

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_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,
    ],
]);
$response = $client->get(
    '/v1/lead',
    [
        'query' => [
            'd_create_start' => '2021-02-16T09:25:43+00:00',
            'd_create_end' => '2021-03-16T09:25:43+00:00',
            'status_id' => [1],
            'type_id' => [1],
        ]
    ]
);
$statusCode = $response->getStatusCode();
$responseData = json_decode((string)$response->getBody(), true);
```

{% endtab %}

{% tab title="Javascript" %}

```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.get("/v1/lead", {
    params: data
})
.then(function (response) {
    console.log(response);
})
.catch(function (error) {
    console.log(error);
});
```

{% endtab %}
{% endtabs %}

## Получить заявку

<mark style="color:blue;">`GET`</mark> `https://api.lpmotor.ru/v1/lead/{lead_id}`

#### Path Parameters

| Name     | Type    | Description |
| -------- | ------- | ----------- |
| lead\_id | integer | ID заявки   |

#### Headers

| Name          | Type    | Description     |
| ------------- | ------- | --------------- |
| X-Api-User-Id | integer | ID пользователя |
| Authorization | string  | API-токен       |

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

```
{
  "id": int,
  "page_id": int,
  "name": "string",
  "phone": "string",
  "email": null,
  "ip": "string",
  "ip_banned": 0,
  "is_del": 0,
  "type_id": 2,
  "status_id": 1,
  "f_expense": 0,
  "f_profit": 0,
  "kanban_position": 0,
  "status": {
    "id": 1,
    "class": "new"
  },
  "type": {
    "id": 2,
    "class": "order"
  },
  "d_created": "string",
  "history": [
    {
      "id": 0,
      "typeId": null,
      "statusId": null,
      "message": "string",
      "d_created": "string"
    }
  ],
  "page": {
    "id": 0,
    "user_id": 0,
    "name": "string",
    "url": "string",
    "site_id": 0,
    "is_enabled": false,
    "d_last_change": "string",
    "site": {
      "id": 0,
      "title": "string",
      "subdomain": "string",
      "attached_domain": "string",
      "is_del": false
    },
    "is_base_variant": false,
    "is_variant": false,
    "variant_name": "string"
  },
  "cart": null,
  "total_price": 234
}
```

{% 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 GET "https://api.lpmotor.ru/v1/lead/<<lead_id>>"
```

{% endtab %}

{% tab title="PHP CURL" %}

```php
<?php
$ch = curl_init();
$url = 'https://api.lpmotor.ru/v1/lead/' . $leadId;

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_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,
    ],
]);
$response = $client->get('/v1/lead/' . $leadId);
$statusCode = $response->getStatusCode();
$responseData = json_decode((string)$response->getBody(), true);
```

{% endtab %}

{% tab title="Javascript" %}

```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.get("/v1/lead/" + leadId)
.then(function (response) {
    console.log(response);
})
.catch(function (error) {
    console.log(error);
});
```

{% endtab %}
{% endtabs %}

## Создать заявку

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

#### Headers

| Name          | Type    | Description     |
| ------------- | ------- | --------------- |
| X-Api-User-Id | integer | ID пользователя |
| Authorization | string  | API-токен       |

#### Request Body

| Name       | Type   | Description          |
| ---------- | ------ | -------------------- |
| page\_id   | string | ID страницы          |
| status\_id | string | ID статуса заявки    |
| type\_id   | string | ID типа заявки       |
| ip         | string | IP пользователя      |
| name       | string | Имя пользователя     |
| email      | string | Email пользователя   |
| phone      | string | Телефон пользователя |
| comment    | string | Комментарий к заявке |
| f\_income  | string | Сумма сделки         |

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

```
{
  "id": int,
  "page_id": int,
  "name": "string",
  "phone": "string",
  "email": null,
  "ip": "string",
  "ip_banned": 0,
  "is_del": 0,
  "type_id": 2,
  "status_id": 1,
  "f_expense": 0,
  "f_profit": 0,
  "kanban_position": 0,
  "status": {
    "id": 1,
    "class": "new"
  },
  "type": {
    "id": 2,
    "class": "order"
  },
  "d_created": "string",
  "history": [
    {
      "id": 0,
      "typeId": null,
      "statusId": null,
      "message": "string",
      "d_created": "string"
    }
  ],
  "page": {
    "id": 0,
    "user_id": 0,
    "name": "string",
    "url": "string",
    "site_id": 0,
    "is_enabled": false,
    "d_last_change": "string",
    "site": {
      "id": 0,
      "title": "string",
      "subdomain": "string",
      "attached_domain": "string",
      "is_del": false
    },
    "is_base_variant": false,
    "is_variant": false,
    "variant_name": "string"
  },
  "cart": null,
  "total_price": 234
}
```

{% 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/lead" \
-d "{page_id: <<page_id>>, status_id: <<status_id>>, type_id: <<type_id>>}"
```

{% endtab %}

{% tab title="PHP CURL" %}

```php
<?php
$ch = curl_init();
$url = 'https://api.lpmotor.ru/v1/lead';
$data = [
    'page_id'   => $pageId,
    'status_id' => $statusId,
    'type_id'   => $typeId,
];

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 = [
    'page_id'   => $pageId,
    'status_id' => $statusId,
    'type_id'   => $type_id,
];
$response = $client->post(
    '/v1/lead',
    [
        'json' => $data,
    ]
);
$statusCode = $response->getStatusCode();
$responseData = json_decode((string)$response->getBody(), true);
```

{% endtab %}

{% tab title="Javascript" %}

```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/lead", {
    page_id  : pageId,
    status_id: statusId,
    type_id  : typeId
})
.then(function (response) {
    console.log(response);
})
.catch(function (error) {
    console.log(error);
});
```

{% endtab %}
{% endtabs %}

## Обновить статус заявки

<mark style="color:purple;">`PATCH`</mark> `https://api.lpmotor.ru/v1/lead/{lead_id}/status`

#### Path Parameters

| Name     | Type    | Description |
| -------- | ------- | ----------- |
| lead\_id | integer | ID заявки   |

#### Headers

| Name          | Type    | Description     |
| ------------- | ------- | --------------- |
| X-Api-User-Id | integer | ID пользователя |
| Authorization | string  | API-токен       |

#### Request Body

| Name       | Type    | Description              |
| ---------- | ------- | ------------------------ |
| status\_id | integer | ID нового статуса заявки |

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

```
{
  "id": 0,
  "page_id": 0,
  "name": "string",
  "phone": "string",
  "email": "string",
  "ip": "string",
  "ip_banned": 0,
  "is_del": 0,
  "type_id": 0,
  "status_id": 0,
  "f_expense": 0,
  "f_profit": 0,
  "kanban_position": 0,
  "d_created": "string",
  "page": {
    "id": 0,
    "user_id": 0,
    "name": "string",
    "url": "string",
    "site_id": 0,
    "is_enabled": true,
    "d_last_change": "string",
    "site": {
      "id": int,
      "title": "string",
      "subdomain": "string",
      "attached_domain": "string",
      "is_del": false
    },
    "is_base_variant": false,
    "is_variant": false,
    "variant_name": "string"
  },
  "cart": null,
  "total_price": 0
}
```

{% 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 PATCH "https://api.lpmotor.ru/v1/lead/<<lead_id>>/status" \
-d "{status_id: <<status_id>>}"
```

{% endtab %}

{% tab title="PHP CURL" %}

```php
<?php
$ch = curl_init();
$url = 'https://api.lpmotor.ru/v1/lead/' . $leadId. '/status';
$data = ['status_id' => $statusId];

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, "PATCH");
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 = ['status_id' => $statusId];
$response = $client->patch(
    '/v1/lead/' . $leadId . '/status',
    [
        'json' => $data,
    ]
);
$statusCode = $response->getStatusCode();
$responseData = json_decode((string)$response->getBody(), true);
```

{% endtab %}

{% tab title="Javascript" %}

```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.patch("/v1/lead/" + leadId + "/status", {status_id: statusId})
.then(function (response) {
    console.log(response);
})
.catch(function (error) {
    console.log(error);
});
```

{% endtab %}
{% endtabs %}

## Удалить заявку

<mark style="color:red;">`DELETE`</mark> `https://api.lpmotor.ru/v1/lead/{lead_id}`

#### Path Parameters

| Name     | Type    | Description         |
| -------- | ------- | ------------------- |
| lead\_id | integer | ID удаляемой заявки |

#### Headers

| Name          | Type    | Description     |
| ------------- | ------- | --------------- |
| X-Api-User-Id | integer | ID пользователя |
| Authorization | string  | API-токен       |

{% tabs %}
{% tab title="204 Заявка успешно удалена" %}

```
```

{% 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 DELETE "https://api.lpmotor.ru/v1/lead/<<lead_id>>"
```

{% endtab %}

{% tab title="PHP CURL" %}

```php
<?php
$ch = curl_init();
$url = 'https://api.lpmotor.ru/v1/lead/' . $leadId;

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, "DELETE");
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
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);

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,
    ],
]);
$response = $client->delete('/v1/lead/' . $leadId);
$statusCode = $response->getStatusCode();
```

{% endtab %}

{% tab title="Javascript" %}

```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.delete("/v1/lead/" + leadId)
.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/zayavki/leads.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.
