How to get chats and messages via API
Chats and messages via the API are read in two requests: first the list of bot chats, then the messages of the specific chat. This is the same as opening the bot in the application and tapping on a co
Chats and messages via the API are read in two requests: first the list of bot chats, then the messages of the specific chat. This is the same as opening the bot in the application and tapping on a conversation.
This article covers how to get a list of chats, paginate, find a specific chat, read the conversation, and convert operator, tag, and field IDs into readable names.
What you will need
- API key with the Space viewer role or higher. Which role to choose — in the article API Key Permissions: Which Role to Assign.
- Bot ID. How to find it — in the article First API request in 5 minutes.
Get the list of bot chats
The list of bot chats is returned by
POST /chats/v1/search with bot_id in the body. Chats with the most recent messages come first:POST
https://api.chatterfy.ai/public-api/chats/v1/search
List of bot chats
Запросbash
curl -X POST 'https://api.chatterfy.ai/public-api/chats/v1/search' \
-H 'ApiKey: ВАШ_КЛЮЧ' \
-H 'Content-Type: application/json' \
-d '{"bot_id": "ID_БОТА", "limit": 50}'Field | Required | Description |
|---|---|---|
bot_id | Yes | Bot ID |
limit | No | Number of chats per page: from 1 to 100; default is 25 |
sort | No | desc — newest messages first (default), asc — reverse order |
filter | No | Filter conditions: status, tags, dates, and others. More details in the article Chat filters in the API |
cursor | No | The next page token from the previous response |
Paginate through the chat list
One page of the chat list contains no more than 100 chats. Subsequent pages are requested using
cursor and has_more:Check pagination
If the response containshas_more: true, there are more chats.next_cursorcontains the next page token.Repeat the request with a cursor
Send the same request and add thecursorfield with the value ofnext_cursor. Do not change other fields.Тело запроса второй страницыjson{ "bot_id": "ID_БОТА", "limit": 50, "cursor": "ЗНАЧЕНИЕ_NEXT_CURSOR" }Stop on the last page
On the last page,has_more: false, andnext_cursoris missing.
Search retrieves up to 10,000 chats
Beyond the 10,000th chat, the API will return a
cursor_out_of_range error. To retrieve more, use export — How to export all chats via API.The list changes while you are reading it: a chat with a new message moves to the top. If you are collecting chats into a table, remove duplicates by
id.Find a specific chat by name, username, or id
To find a chat by customer name, username, or Telegram id, pass the
query filter:Тело запросаjson
{
"bot_id": "ID_БОТА",
"filter": { "field": "query", "value": "Анна" }
}The chat list is taken from the search index, which lags behind the real state by a second or two. To get the chat exactly in its current state, request it by id via
GET /chats/v1/{chat_id}:GET
https://api.chatterfy.ai/public-api/chats/v1/{chat_id}
A single chat by id
Запросbash
curl 'https://api.chatterfy.ai/public-api/chats/v1/ID_ЧАТА' \
-H 'ApiKey: ВАШ_КЛЮЧ'Chat fields in the API response
What is returned in each chat from
POST /chats/v1/search and GET /chats/v1/{chat_id}:Field | Meaning |
|---|---|
id | Chat id |
name, username | Client name and username in Telegram. Without the chat.contacts.read permission, they arrive hidden |
external_id | Client ID in Telegram |
status | Chat status: ai — Auto, manual — Manual, as well as waiting, ignore, blocked, error, stopped, finished. What they mean is in the article Chat Status — conversation statuses |
assign_id | Assignee ID. Name — in the Space member list, below |
tags | Chat tag IDs |
custom_fields | Chat fields: field id, its key, and value |
last_message | Last message with all fields |
read_state.incoming_unread_count | Number of unread client messages |
lead | |
created_at | When the chat was created |
Read chat messages
Messages for a single chat are retrieved via
POST /messages/v1/search with chat_id in the body. Without the type field, both messages and system events will be returned:POST
https://api.chatterfy.ai/public-api/messages/v1/search
Messages of a single chat
Запросbash
curl -X POST 'https://api.chatterfy.ai/public-api/messages/v1/search' \
-H 'ApiKey: ВАШ_КЛЮЧ' \
-H 'Content-Type: application/json' \
-d '{"chat_id": "ID_ЧАТА", "limit": 50, "order": "desc", "type": "message"}'Field | What it means |
|---|---|
chat_id | Chat ID. Required field |
limit | Number of messages per page: up to 100, default is 25 |
order | desc — newest first (default), asc — oldest first |
type | message — messages only, event — system events only (like tag or status changes). If omitted, both will be returned |
cursor | Next page marker |
Message pages are navigated the same way as chat pages: using
cursor and has_more.Message fields in the API response
What is returned in each message from
POST /messages/v1/search:Сообщение (часть полей скрыта)json
{
"id": "e1a7c3d9-4b2f-4e8a-9c6d-0f5b2a7e3c18",
"chat_id": "9d4e1b27-3c8a-4f6e-b2d1-7a5c0e8f3b62",
"type": "message",
"status": "ready",
"content": "Здравствуйте! Сколько стоит доставка?",
"sender_type": "incoming",
"read": true,
"files": [],
"created_at": "2026-10-28T09:15:42Z"
}Field | Meaning |
|---|---|
content | Message text |
sender_type | incoming — from the client, outcoming — from your side |
sender | ID of the operator who sent the message. Empty if sent by a bot |
status | ready — sent, waiting — sending, schedule — scheduled, failed — failed to send, reason is in error |
files | Attachments: type ( photo, document, etc.) and url |
reply_message_id | ID of the message to which this message is a reply |
is_mailing | true if the message came from a mailing list |
edited_at | When the message was edited |
Convert operator, tag, and field IDs into names
People, tags, and fields in chats and messages are identified by ID. To show names, request the directories:
- Space members —
POST /spaces/v1/{space_id}/members/search.space_idis available in the bot data. The response contains two lists:accounts— employees andservice_accounts— service accounts.
- Bot tags —
GET /bots/v1/{bot_id}/tags:id,name, andcolorof each tag.
- Bot fields —
GET /bots/v1/{bot_id}/custom-fields:id,key,name, andtypeof each field.
Участники Spacebash
curl -X POST 'https://api.chatterfy.ai/public-api/spaces/v1/ID_SPACE/members/search' \
-H 'ApiKey: ВАШ_КЛЮЧ'Directories change rarely. Request them once and store them locally, rather than before each chat.
FAQ
Related
Was this article helpful?

