# Пользовательские переменные

{% hint style="warning" %}
Как правильно сформировать запрос?! Смотрим в [основах](/dlya-razrabotchikov/dokumentaciya-i-rabota-s-api/osnovy.md)
{% endhint %}

## Получить список переменных

<mark style="color:blue;">`GET`</mark> `https://app.cleverapp.pro/api/v1/getContactVariables`

Этот метод позволяет получить список пользовательских переменных для определенного контакта.

#### Path Parameters

| Name                                          | Type    | Description  |
| --------------------------------------------- | ------- | ------------ |
| contact\_id<mark style="color:red;">\*</mark> | integer | ID контакта. |

{% tabs %}
{% tab title="200: OK Запрос успешно обработан" %}

```javascript
{
  "data": [
    {
      "id": 16497876867449,
      "name": "Имя переменной",
      "value": "Значение переменной",
      "deletable": false,
      "variable": {
        "id": 16497876867449,
        "name": "Имя переменной"
      }
    },
    {
      "id": 16497893703850,
      "name": "Город",
      "value": "Москва",
      "deletable": false,
      "variable": {
        "id": 16497893703850,
        "name": "Город"
      }
    }
  ]
}
```

{% endtab %}

{% tab title="422: Unprocessable Entity Переданные данные некорректны" %}

```javascript
{
  "message": "The given data was invalid.",
  "errors": {
    "contact_id": [
      "Поле contact id обязательно для заполнения."
    ]
  }
}
```

{% endtab %}
{% endtabs %}

## Создать/обновить переменную

<mark style="color:green;">`POST`</mark> `https://app.cleverapp.pro/api/v1/setContactVariable`

Этот метод позволяет создать или обновить пользовательскую переменную. Если такой переменной не существует в боте, то она создастся и привяжется к пользователю.

#### Query Parameters

| Name                                          | Type    | Description                                                                                                                          |
| --------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| contact\_id<mark style="color:red;">\*</mark> | integer | ID контакта.                                                                                                                         |
| name<mark style="color:red;">\*</mark>        | string  | Имя переменной.                                                                                                                      |
| value<mark style="color:red;">\*</mark>       | string  | Значение переменной.                                                                                                                 |
| deletable                                     | integer | Возможные значения:`0` - переменная не должна удалиться после заявки`1` - переменная должна удалиться после заявки По умолчанию: `0` |

{% tabs %}
{% tab title="200: OK Переменная успешно создана/отредактирована" %}

```javascript
{
  "data": {
    "id": 16498385181301,
    "name": "Имя переменной",
    "value": "Значение переменной",
    "deletable": false,
    "variable": {
      "id": 16498385181301,
      "name": "Имя переменной"
    }
  }
}
```

{% endtab %}

{% tab title="403: Forbidden Доступ запрещен" %}

```javascript
{
    "message": "Forbidden"
}
```

{% endtab %}

{% tab title="422: Unprocessable Entity Переданы некорректные данные" %}

```javascript
{
  "message": "The given data was invalid.",
  "errors": {
    "contact_id": [
      "Поле contact id обязательно для заполнения."
    ],
    "name": [
      "Поле Имя обязательно для заполнения."
    ],
    "value": [
      "Поле value обязательно для заполнения."
    ]
  }
}
```

{% endtab %}
{% endtabs %}

## Удалить переменную

<mark style="color:green;">`POST`</mark> `https://app.cleverapp.pro/api/v1/deleteContactVariable`

Этот метод позволяет удалить пользовательскую переменную по ее имени или ID.

#### Query Parameters

| Name                                          | Type    | Description                                         |
| --------------------------------------------- | ------- | --------------------------------------------------- |
| contact\_id<mark style="color:red;">\*</mark> | integer | ID контакта                                         |
| id                                            | integer | ID переменной. Обязательно когда `name` не передан. |
| name                                          | string  | Имя переменной. Обязательно когда `id` не передан.  |

{% tabs %}
{% tab title="204: No Content Переменная успешно удалена" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="403: Forbidden Доступ запрещен" %}

```javascript
{
    "message": "Forbidden" 
}
```

{% endtab %}

{% tab title="422: Unprocessable Entity Переданы некорректные данные" %}

```javascript
{
  "message": "The given data was invalid.",
  "errors": {
    "id": [
      "Поле id обязательно для заполнения, когда Имя не указано."
    ],
    "contact_id": [
      "Поле contact id обязательно для заполнения, когда id не указано."
    ],
    "name": [
      "Поле Имя обязательно для заполнения, когда id не указано."
    ]
  }
}
```

{% 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://help.cleverapp.pro/dlya-razrabotchikov/dokumentaciya-i-rabota-s-api/kontakty/polzovatelskie-peremennye.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.
