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

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

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

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

#### Path Parameters

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

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

```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 Переданные данные некорректны." %}

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

{% endtab %}
{% endtabs %}

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

<mark style="color:green;">`POST`</mark> `https://watbot.ru/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 | <p>Возможные значения:</p><p><code>0</code> - переменная не должна удалиться после заявки</p><p><code>1</code> - переменная должна удалиться после заявки</p><p>По умолчанию: <code>0</code></p> |

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

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

{% endtab %}

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

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

{% endtab %}

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

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

{% endtab %}
{% endtabs %}

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

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

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

#### Query Parameters

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

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

{% endtab %}

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

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

{% endtab %}

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

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

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Объект `data.variable` устарел и теперь передается в ответе только для совместимости старого API. Окончательно перестанет поддерживаться после 01.03.2023&#x20;
{% endhint %}


---

# 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://docs.watbot.ru/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.
