# QR code and barcode: generation and recognition

## QR-code generation

To generate a code, you need to use the function <https://store.mavibot.ai/function/qrcode\\_generator&#x20>;

#### Parameters:&#x20;

**text\_for\_qr** - text that needs to be coded \
**api\_key** - API access key from the project’s settings

![You can generate a code in the project’s settings](https://lh6.googleusercontent.com/G3P9JaFTZGHPGvVwzzehQy0mdgSHib6jodk5ABNL426isLQtkDmfduUrAmufT2ExI9ecJXPlTGdhywYGP5X6oGxTTu_QbsqTIE1A9RE4Qr5kVQIpkR8O3mL0-NTKuasuf2o73Kga_LD6s_hc7w)

{% hint style="info" %}
Change #{api\_key} to the token from settings
{% endhint %}

#### Example:

In the "URL request" field paste: <https://store.mavibot.ai/function/qrcode\\_generator>

In the "Stored values" field paste the variables you want to save (the required URL is in *qr\_image\_url*):

*status->status;*&#x20;

*qr\_image\_url->qr\_image\_url*

In "JSON parameters" type

*{"text\_for\_qr":"Text for coding","api\_key":"8629fe13ba9efebefd27a7afd701767f"}*

<figure><img src="/files/zSv3OPlQ3CoaFW14ZqMN" alt="" width="563"><figcaption></figcaption></figure>

The function returns json with parameters *status* and *qr\_image\_url*

![The QR-code you get](https://lh6.googleusercontent.com/eSuVmN8FWyY6t7zXmyghnfXLbSy4S5u_Di4oryW3beBhQNZVXLXMPdve7wpx3fvqmbvYAL8J3XWn4gNff9R5pVFp04OjhgOqfJnS-kbC_kZnCV6iPO2JlJeL11TYUJ-mRij7eWVllrLlGeRZsA)

## Barcode generation

To generate a code, you need to use the function <https://store.mavibot.ai/function/barcode\\_generator&#x20>;

#### Parameters:&#x20;

**text\_for\_qr** - text that needs to be coded \
**api\_key** - API access key from the project’s settings

![You can generate an API access key in the project's settings](https://lh5.googleusercontent.com/cWMoOIdWMMRt6-EDnJvQXFRSsEZaTJNUnXZwcVBrBUmK19nZ_coUel3BXdrxT1sBn6L5qitVUu1-xbYuks6qsC8mxsEUGJ1u6ctNoYkFQaoLRLO4X32XupBFtVDxKuMSIY6G-Wsj_VcMqVrZPA)

**class** - the code class you need to generate. By default it’s ea13. Can take these values: *'code39', 'code128', 'ean', 'ean13', 'ean8', 'gs1', 'gtin', 'isbn', 'isbn10', 'isbn13', 'issn', 'jan', 'pzn', 'upc', 'upca'*

**without\_text** - (an optional parameter) if you provide it with any value, the barcode will be displayed without the text, as shown in the image below.

![](https://lh5.googleusercontent.com/VXAHILxb5iktDtp4u8t6DzuQ3mfCWi-UX-XuPQ_cuSd9lvQTMEMgrcH8q7ZuqnJjRsHT5czWg_ra1RGxAVSm7OJe3nQeSI5Yu5zrvSQSxBBNB6wR-zzfuy9XEVRxTBlyv41nvKk8aaxt0fUJrQ)

{% hint style="info" %}
Change #{api\_key} to the token from settings
{% endhint %}

Example: *{"text":"#{barcode}","api\_key":"#{api\_key}", "class": "ean13"}*&#x20;

The function returns json with parameters *status* and *qr\_image\_url* if successful and *error\_message* if unsuccessful

![](https://lh5.googleusercontent.com/d5iQRmdgfMrKI5_lnMzriTnyMcWm_slw4Mj5kArjxkOcGJzm5OIlRflLzqrwOe8OUdwyVl12fHC5yWQAs26g6cWuMTJoreO3cIE4HBFbBKrgZvrykg8onW4xZBIMaBGtUkhUbvXmVQLDJ-MaJw)

{% hint style="info" %}
The example text is stored in the variable barcode, and the variable image\_url is used to send it as an image.
{% endhint %}

![An example of the request with no text](https://lh6.googleusercontent.com/LOJir5XWjFLkuValhnA6WDmsDIDfXS_RZ-dtSuuN5ZJBrnTdSPmXU1SqtVcKab6yEpsLi-ZsuIRQhjbZuM3XJt9HuGf7bd_stOygSXYLPh2FJFoxEONy9ZZJOmR_R1X-nsHBdFk47_FFo_lFpA)

## Barcode recognition from an image

You can use this for creating a bot that scans product codes. A useful feature is the fact that it can also scan QR-codes.

The address of the function that recognizes a barcode on an image is <https://store.mavibot.ai/function/cv2barcode&#x20>;

To scan an image you need to send these parameters from the block:

*{"photo":"the link to the barcode/QR-code or the variable with the link","api\_key":"api access key from the settings"}*

For example, to send an image for scanning you need to send these parameters:

![](https://lh6.googleusercontent.com/xbJz5HRo4PX_phHU5OW0j9GGANrH6sconYSdOwIW7iE-BtJwYibjv3DMZ0-UqebJaZ54TrCxH2sCFxcF3mEMEQFqdWDj4OHIf9_D5lmKn47Ye3rQ7cd6wZO6bPFfTm6OIbe90qUFBC_CYPCPgA)

In the arrow in the "User enters data" field enter the variable #{attachments}.

Code example:

`{"photo":"#{attachments}","api_key":"8629fe13ba9efebefd27a7afd701767f"}`&#x20;

`photo` is the link to the barcode image; in our case, it’s the variable that holds the link to the image sent to the bot.

The next parameter is **api\_key** - API access key from the project’s settings

![](https://lh6.googleusercontent.com/acBPr_Z1ewC3iC32xGYyy-l1LItVnkfdtIByxUYCbujBANi7KTfcce9mnBMl9jA4foxKv6Z75dp7fCiNBVFOKVE60EFOnhdrh2wH_eEDesvWQTO-mDYVUXCxeZTHoLv4p8RHhrr0qhhXnMmOqQ)

The function works like this:

The client sends a picture of the barcode, the function scans it, and if successful, returns the barcode number with the operation status set to "ok."

barcode -> "4500000000567" status -> "ok"

The scanning status can be:

* **ok** — the barcode was recognized
* **barcode not recognized** — as the name suggests, the barcode couldn’t be recognized
* **error image reading** — there was an error reading the image
* **error subscription** — this feature isn’t available with your current subscription plan

The variable status can be used as a condition on an arrow to direct the client to the appropriate block.

For example, if an arrow’s condition checks whether status equals “barcode not recognized,” you can display the message "The code wasn’t recognized, please try again" and prompt the client to send the photo again.


---

# 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/special-features/qr-code-and-barcode-generation-and-recognition.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.
