# Working with MaviBot tags

## Create / remove label

create\_label() | add\_label() | remove\_label() | remove\_label\_everywhere() | count\_of\_clients\_with\_label() | has\_label()

<details>

<summary>Description</summary>

MaviBot tags are displayed in a customer profile as:

<div data-with-frame="true"><figure><img src="/files/Q9PuTNO0R7cmkNVdUxXC" alt="" width="355"><figcaption><p>Tags in a customer profile</p></figcaption></figure></div>

and in the **"Lists"** section:

<div data-with-frame="true"><figure><img src="/files/deAdN10Hz3sx1gOUAitZ" alt=""><figcaption></figcaption></figure></div>

**create\_label(label\_name)**\
creates MaviBot tag with specified name

Parameters:\ <mark style="color:red;">**!**</mark>**&#x20;label\_name**- tag name, specified in single quotation marks ('').

**add\_label(label\_name, client\_id)**\
add MaviBot tag to client&#x20;

Parameters:\ <mark style="color:red;">**!**</mark>**&#x20;label\_name -** tag name, specified in single quotes ('')\
**client\_id** client ID. If omitted, current client ID is used&#x20;

**remove\_label(label\_name, client\_id)**\
remove tag fom client&#x20;

Parameters:\ <mark style="color:red;">**!**</mark>**&#x20;label\_name** - tag name, specified in single quotes ('')\
**client\_id** -client ID. If omitted, current client ID is used

**has\_label(label\_name, client\_id**) - check if client has tag&#x20;

Parameters:\ <mark style="color:red;">**!**</mark>**&#x20;label\_name** - tag name, specified in single quotes ('')\
**client\_id** - client ID. If omitted, current client ID is used

**remove\_label\_everywhere(label\_name)**\
remove tag from all clients

Parameters:\ <mark style="color:red;">**!**</mark>**&#x20;label\_name**- tag name, specified in single quotes ('')

**count\_of\_clients\_with\_label(label\_name)**\
get total number of clients with tag

Parameters:\ <mark style="color:red;">**!**</mark>**&#x20;label\_name**- tag name, specified in single quotes ('')

</details>

<details>

<summary>Example</summary>

So, let’s see **how a MaviBot tag is created**.

You just need to execute the creation function once in the gray block (a non-state block), for example:

<div data-with-frame="true"><figure><img src="/files/pcOdiuOh5APzibzZvDrC" alt=""><figcaption><p>   Creating a tag using the calculator function</p></figcaption></figure></div>

At the same time, the variable ***a*** can be used to analyze the success of the tag creation function:

<div data-with-frame="true"><figure><img src="/files/6ORubEm1qL7KxgGbapiP" alt="" width="563"><figcaption></figcaption></figure></div>

Next, you can **assign a tag to any client** by adding the `add_label()` function in the appropriate block of your funnel:

<div data-with-frame="true"><figure><img src="/files/NNxt7zxEwB99NPNqECyo" alt="" width="563"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/6oAdwizYzkuO6CaDRjTu" alt="" width="375"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/bMSgGHPTdtpuCEX1SsFP" alt="" width="319"><figcaption></figcaption></figure></div>

You can check if a client has a tag using the `has_label()` function:

<div data-with-frame="true"><figure><img src="/files/vzBCW4OoZpOR8nsy6O9p" alt=""><figcaption></figcaption></figure></div>

The function returns a logical value: True or False.&#x20;

<div data-with-frame="true"><figure><img src="/files/PwWgaN2V37ZTvXFPTVAz" alt=""><figcaption></figcaption></figure></div>

**Other tag-related actions are performed similarly**—removing a tag from a specific client or removing a tag entirely from all clients.

You can also count the number of clients with a given tag by using the `count_of_clients_with_label()` function.

<div data-with-frame="true"><figure><img src="/files/5gv4DkoxrDahkMrGvlja" alt="" width="375"><figcaption><p>Counting the number of clients by a given tag</p></figcaption></figure></div>

</details>

<details>

<summary>Code example for copying</summary>

`/Create tag/ a=create_label('tag1')`

`/Assign tag to client/ a=add_label('stage 1')`

`/Check if client has tag/ a=has_label('этап 1','73704021')`

`/Count number of clients with given tag/ etap1=count_of_clients_with_label('stage 1') tovar1=count_of_clients_with_label('1')`

</details>

## Creating a tag

<details>

<summary>Description</summary>

**create\_label(label\_name)** - creates MaviBot tag with specified name

Parameters:

<mark style="color:red;">**!**</mark>**&#x20;label\_name**- tag name, specified in single quotes ('')

</details>

### Creating a tag  without duplicates

<details>

<summary>Description</summary>

**create\_label\_if\_not\_exist(name, color) -** creates a new tag if one with the same name doesn’t exist yet and returns its identifier; otherwise, returns the identifier of the existing tag

**name** — tag name

**color** — tag color (default: 0)

Color table for **color** parameter:

0 — light grey&#x20;

1 — yellow

2 — blue&#x20;

3 — red

4 — pink

5 — beige&#x20;

6 — purple

7 — light blue&#x20;

8 — grey

9 - green

</details>

### Get all client tags

<details>

<summary>Description</summary>

**get\_all\_client\_labels(client\_id)**&#x20;

***Parameters:***

**client\_id** - optional; if not provided, tags of the current client will be retrieved.

The function returns a response in JSON format: {"161":"tag1","228":"tag2"}, where: key is the tag ID, and value is the tag name

</details>

<details>

<summary>Example</summary>

<figure><img src="/files/lEbN6MNDF2B1ENagEjHE" alt="" width="375"><figcaption><p>Get all tags of the current client</p></figcaption></figure>

</details>

### Delete client tags by array

<details>

<summary>Description</summary>

**remove\_multiple\_client\_labels(labels\_array, names) -** deletes tags specified in array

**labels\_array** - tags array. <mark style="color:$primary;">OR</mark> <mark style="color:orange;">**ID**</mark> array<mark style="color:orange;">**,**</mark> <mark style="color:$primary;">OR</mark> <mark style="color:orange;">**names**</mark> array.&#x20;

<mark style="color:orange;">If names array is passed</mark>, then<mark style="color:orange;">❗it is mandatory to pass the second parameter (names) set to 1.</mark>

**names** -  Set to 1, if array contains tag names instead of IDs. This indicates that array consists of names.

{% hint style="danger" %}
It is NOT allowed to combine both tag IDs and tag names in the same function!
{% endhint %}

</details>

<details>

<summary>Example</summary>

`/*Delete tags by ID*/`

`r = remove_multiple_client_labels('[138,169,166]')`&#x20;

`/*Delete tags by tag name*/`

`r2 = remove_multiple_client_labels('["newTestTag","tag2"]', 1)`

The variable stores the result of the function execution: either an error message or a number indicating how many tags were deleted.

<div data-with-frame="true"><figure><img src="/files/lEMz9MrslYe19PCjI2n9" alt="" width="563"><figcaption></figcaption></figure></div>

</details>

### Find clients by multiple tags

<details>

<summary>Description</summary>

**find\_clients\_by\_multiple\_labels(labels\_array, names)** - finds clients by multiple tags

{% hint style="warning" %}
IMPORTANT! This finds only those clients who have ALL specified tags.
{% endhint %}

Parameters:

**labels\_array** - tags array. <mark style="color:$primary;">OR</mark> <mark style="color:orange;">**ID**</mark> array<mark style="color:orange;">**,**</mark> <mark style="color:$primary;">OR</mark> <mark style="color:orange;">**names**</mark> array.&#x20;

<mark style="color:orange;">If names array is passed</mark>, then<mark style="color:orange;">❗it is mandatory to pass the second parameter (names) set to 1.</mark>

**names** -  Set to 1, if array contains tag names instead of IDs. This indicates that array consists of names.

{% hint style="danger" %}
It is NOT allowed to combine both tag IDs and tag names in the same function!
{% endhint %}

Returns an array of client IDs (client\_id): \[41121, 41192, 41522]

</details>

<details>

<summary>Example</summary>

`/*Find clients who have all specified tags by ID*/`

`r = find_clients_by_multiple_labels('[138,169,166]')`&#x20;

`/*Find clients who have all specified tags by tag names*/`

`r2 = find_clients_by_multiple_labels('["newTestTag","tag2"]', 1)`

<div data-with-frame="true"><figure><img src="/files/seLq9BRX2W1HoFIpbtHS" alt="" width="563"><figcaption></figcaption></figure></div>

</details>

### Check array of client tags

<details>

<summary>Description</summary>

**has\_client\_multiple\_labels(labels\_array, names)** - checks array of client tags

{% hint style="warning" %}
IMPORTANT! It returns **True** if a client has all specified tags!
{% endhint %}

Parameters:

**labels\_array** - tags array. <mark style="color:$primary;">OR</mark> <mark style="color:orange;">**ID**</mark> array<mark style="color:orange;">**,**</mark> <mark style="color:$primary;">OR</mark> <mark style="color:orange;">**names**</mark> array.&#x20;

<mark style="color:orange;">If names array is passed</mark>, then<mark style="color:orange;">❗it is mandatory to pass the second parameter (names) set to 1.</mark>

**names** -  Set to 1, if array contains tag names instead of IDs. This indicates that array consists of names.

{% hint style="danger" %}
It is NOT allowed to combine both tag IDs and tag names in the same function!
{% endhint %}

Returns either **an error**, or **True** if client has all tags from the array, or **False** if client doesn’t have all tags.

</details>

<details>

<summary>Example</summary>

`/*Check if client has all specified tags by ID*/`

`r = has_client_multiple_labels('[138,169,166]')`

`/*Check if client has all specified tags by tag names*/`

&#x20;`r2 = has_client_multiple_labels('["newTestTag","tag2"]', 1)`

<div data-with-frame="true"><figure><img src="/files/VRCWKZNURhbdx2PrRFUY" alt="" width="563"><figcaption></figcaption></figure></div>

</details>


---

# 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.mavibot.ai/chatbot/functions/calculator/tags.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.
