# Working with MaviBot tables

## Create a new record in the table with the specified values

Create a new record in a table with the specified values.

new\_record(table\_id, data)

<table><thead><tr><th width="188.26171875">Params</th><th>Description</th></tr></thead><tbody><tr><td>table_id </td><td>table ID</td></tr><tr><td>data</td><td>a dictionary with the data to be recorded.<br><br>Example: {"column_name1": "value1", "column_name2": "value2"}. If the column does not exist, it is created.</td></tr></tbody></table>

Response: new record ID

### Example

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

## Edit an existing record in the table

edit\_record(table\_id, record\_id, data)

<table><thead><tr><th width="304.22265625">Params</th><th>Description</th></tr></thead><tbody><tr><td>table_id</td><td>table ID</td></tr><tr><td>record_id</td><td>edited record ID</td></tr><tr><td>data</td><td>a dictionary with the data to be edited. Example: {"column_name1": "value3", "column_name2": "value4"}. If the column does not exist, it is NOT created.</td></tr></tbody></table>

Response:

Returns the full data of the edited record in the format: {"column\_name1": "value3", "column\_name2": "value4"}.

### Example

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

## Delete a record from the table by its ID

delete\_record(table\_id, record\_id)

<table><thead><tr><th width="298.4140625">Params</th><th>Decription</th></tr></thead><tbody><tr><td>table_id</td><td>table ID</td></tr><tr><td>record_id</td><td> deleted record ID</td></tr></tbody></table>

Response:

{'message': 'Deleted records: 1'}

## Find a record in the table by the specified value

find\_record(table\_id, value, find\_in, return\_from)

<table><thead><tr><th width="304.22265625">Params</th><th>Description</th></tr></thead><tbody><tr><td>table_id</td><td>table ID</td></tr><tr><td>value</td><td>the value to match</td></tr><tr><td>find_in - </td><td>optional parameter. The name of the column to search by. If not specified, the search will be performed across all columns.</td></tr><tr><td>return_from</td><td>optional parameter. The name of the column from which to return the value.</td></tr></tbody></table>

Response:

If return\_from is specified, the value from the specified column (if it exists in the table) will be returned. If return\_from is not specified or the column does not exist, the full data of the found record will be returned in the response, for example: {"column\_name1": "value3", "column\_name2": "value4"}.

### Example

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

## Retrieving a value from the specified record

get\_record\_data(table\_id, record\_id)

<table><thead><tr><th width="298.4140625">Params</th><th>Decription</th></tr></thead><tbody><tr><td>table_id</td><td>table ID</td></tr><tr><td>record_id</td><td>record ID from which the values are retrieved</td></tr><tr><td>return_column</td><td>optional parameter. The name of the column from which the value should be returned.</td></tr></tbody></table>

Response: If a record is found, a dictionary like {"column\_name1": "value1", "column\_name2": "value2"} is returned. If the return\_column parameter is provided and such a column exists, only the value from that column will be returned.

### Where can I find a table ID?

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

To work with chatbot functions, you'll need the table ID. Find the desired table in the list and click on it.

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

Next, click the address bar.

In the address bar, you will see a URL like&#x20;<https://salebot.pro/projects/11111/table/2>,&#x20;where you can find the ID of the desired table:

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

## Retrieving a record from the table

get\_records\_from\_table(table\_id, start\_row, count, start\_col, end\_col) - retrieving a record from the table.

| Parameter  | Description                                                               | Note                                                                                        |
| ---------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| table\_id  | table ID                                                                  |                                                                                             |
| start\_row | Optional parameter, an integer. Specifies the start of the row range.     | The row number to start reading from (inclusive). Write it without quotation marks.         |
| count      | Optional parameter, an integer. Specifies the number of rows to retrieve. | By default, the value is 1000, with a maximum of 5000. Specify without quotation marks.     |
| start\_col | Optional parameter, a string. Specifies the start of the column range.    | The name of the column to start reading from (inclusive). Write it in quotation marks.      |
| end\_col   | Optional parameter, a string. Specifies the end of the column range.      | The name of the column to read up table values to (inclusive). Write it in quotation marks. |

If you specify only the start of the row or column range, all data from that point on will be returned. You can also leave out the start and specify only the end to get data up to that point.

### Example

In the block where you need to retrieve records from the table, go to the **"Calculator"** section in the block settings and enter the function with the required parameters.

Let's see how the data is displayed in the table.

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

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

Now, execute the "Start" block in test mode.

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

We can see the data that was written to the variable from the table in the message sent by the bot. Because we referenced the variable in the message using the `#{}` syntax, the data stored in it was displayed in the bot chat.

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

## Retrieve data from the table within a specified range

table\_read\_cells(table\_id, cell\_data) - allows retrieving data from the table by specifying ranges.

<table><thead><tr><th width="286.37890625">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark> table_id</td><td>required parameter, table ID</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark> cell_data</td><td>required parameter, a dictionary with ranges.<br><strong>cell_data</strong> example: <code>'{"a1":"a1", "a3": "b4", "c1": "c3"}'</code></td></tr></tbody></table>

If no issues occurred during the request, the response will be a dictionary containing the status and all cells with their values:

`{"status": true, "A1": "value", "A3": "value", "B3": "value", "A4": "value", "B4": "value", "C1": "", "C2": "value", "C3": "ddddddd"or, in case of an error: {"status": false, "err": "Error message or description"}`

### Example in the Calculator

For example, the table cells contain the following specified values:

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

To retrieve data from the table via the bot, pass the required ranges to the functions in the **Calculator**.

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

In the example, the construct #{res}, which holds a variable, helps display in the message the data retrieved using the function and the specified range:

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

If the column names are different (e.g., "Product", "Number", "Amount"), you must specify the range using the format {"Product1":"Amount3"}, where:

• **Product** is the name of the first column\
• **1** indicates it's column number 1\
• **Amount** is the name of the third column\
• **3** indicates it's column number 3

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

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

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


---

# 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/tables.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.
