> For the complete documentation index, see [llms.txt](https://docs.iiagent.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.iiagent.pro/api.md).

# API

Введение

Этот код использует API для отправки и получения сообщений через сервис iiagent.pro. Давай разберем каждый фрагмент.

#### Отправка сообщения:

1. **URL**: `https://api.iiagent.pro/api/v1.0/send_message` — это конечная точка (endpoint) для отправки сообщений.
2. **Данные запроса** (payload):

   ```json
   {
       "chat_id": "c3",
       "message_id": "m1",
       "message": "2+2"
   }
   ```

   * `chat_id` — уникальный идентификатор чата, в который нужно отправить сообщение.
   * `message_id` — уникальный идентификатор сообщения, которое отправляется.
   * `message` — сам текст сообщения (в данном случае "2+2").
3. **API\_KEY** — это токен для авторизации, который должен быть включен в заголовки для получения доступа к API.
4. **Заголовки**:

   ```python
   headers = {
       "Content-Type": "application/json",
       "Authorization": f"Bearer {API_KEY}",
   }
   ```

   Заголовки содержат информацию о формате данных (`application/json`) и токен авторизации (`Bearer {API_KEY}`).
5. **Ответ**:

   ```python
   response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
   print(response.text)
   ```

   Ответ от API выводится на экран, где `response.text` будет содержать результат выполнения запроса.

#### Получение сообщений:

1. **URL**: `https://api.iiagent.pro/api/v1.0/get_messages` — это конечная точка для получения сообщений.
2. **Данные запроса**: json

   ```json
   {
       "chat_id": "c3"
   }
   ```

   Запрос отправляется для получения сообщений из чата с ID `c3`.
3. **Заголовки** аналогичны запросу на отправку сообщения, с включением авторизационного токена.
4. **Ответ**: python

   ```python
   response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
   response.json()
   ```

   Ответ будет в формате JSON и содержать список сообщений для указанного чата.

#### Пример с `curl`:

Для тех, кто работает с командной строкой, приведены примеры того, как можно отправить запрос с помощью `curl`.

#### Общие моменты:

* Все запросы используют формат JSON для данных.
* API требует авторизации через токен.
* API предоставляет возможность отправлять и получать сообщения через чаты с использованием указанных идентификаторов чатов и сообщений.

Эти фрагменты кода можно использовать для интеграции с чат-ботами или мессенджерами для автоматизации отправки и получения сообщений через API.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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 following URL with the `ask` and `goal` query parameters:

```
GET https://docs.iiagent.pro/api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

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.
