GetChatHistory#
Beta version
The functionality is in beta. Features may change and may also work unstably.
The method returns the history of a chat.
The method uses the limits on the number of requests per second.
Request#
To get the history of a chat, you have to execute a request at:
{{apiUrl}}/waInstance{{idInstance}}/getChatHistory/{{apiTokenInstance}}
For apiUrl, idInstance and apiTokenInstance request parameters, refer to the Before you start section.
Request parameters#
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
chatId | string | Yes | Chat identifier - the numeric identifier of an account or of a group chat, or a username with the @ prefix |
Request body example#
{
"chatId": "49547665464"
}
Response#
Response parameters#
An array of objects with the fields:
| Field | Type | Description |
|---|---|---|
type | string | The kind of the message: incoming for incoming ones, outgoing - for outgoing ones |
idMessage | string | The message identifier |
timestamp | integer | The time of the message in UNIX format (in seconds) |
typeMessage | string | The type of the message |
chatId | string | The chat identifier |
chatType | string | The type of the chat: user for personal chats, bot - for a chat with the Meta AI bot, group - for group ones |
chatUsername | string | The username of the contact in the @username form. An empty string for a group.Records saved before the field appeared do not have it |
senderId | string | The numeric identifier of the sender only for type = incoming |
senderName | string | The name of the sender from the Instagram profile. If there is no name in the profile - the username without @only for type = incoming |
senderUsername | string | The username of the sender in the @username formonly for type = incoming |
senderType | string | The type of the sender: user - an account, bot - the Meta AI botonly for type = incoming |
statusMessage | string | The sending status only for type = outgoing |
sendByApi | boolean | The flag shows whether the message was sent from the API only for type = outgoing |
textMessage | string | The text of the message only for typeMessage = textMessage |
downloadUrl | string | The link to download the file. It leads to the Instagram servers and is valid for a limited time |
caption | string | An empty string: the field is kept for backward compatibility. For sharedMessage - the caption of the post |
fileName | string | The name of the file. Always with an extension: if the link has none or it is not recognized, the extension is added from the MIME type |
jpegThumbnail | string | The preview in base64 (a JPEG 90 pixels wide). Only for images and stickers received or sent while the instance is running; for messages of the synchronized history - an empty string |
mimeType | string | The MIME type of the file |
isAnimated | boolean | The flag of an animated attachment |
videoNote | boolean | The flag of a round video message. There are none in Instagram - always false |
sharedType | string | What was shared: post - a feed post, reel - a Reel.only for typeMessage = sharedMessage |
sharedUrl | string | The link to the post on Instagram. only for typeMessage = sharedMessage |
authorId | string | The numeric identifier of the post author. only for typeMessage = sharedMessage |
authorName | string | The name of the post author from their Instagram profile. If there is no name in the profile - the username without @.only for typeMessage = sharedMessage |
authorUsername | string | The username of the post author in the @username form.only for typeMessage = sharedMessage |
contactMessageData | object | The data of the Instagram account that was shared. only for typeMessage = contactMessage |
location | object | The data of the pinned location - the same fields as in the notification: nameLocation, address, jpegThumbnail, latitude, longitude.only for typeMessage = locationMessage |
pollMessageData | object | The data of the poll: name - the question, options - the answer options with the optionName field, multipleAnswers - whether several options can be selected.only for typeMessage = pollMessage; votes in a poll do not get into the journal |
extendedTextMessageData | object | The object with the text field - the emoji of the reaction. An empty string means the reaction is removed.only for typeMessage = reactionMessage |
quotedMessage | object | The data of the quoted message: stanzaId - the message identifier that was replied to or reacted to, participant - the numeric identifier of its author.only for typeMessage = reactionMessage and for messages with quoting |
isForwarded | boolean | The flag indicates whether the message is forwarded |
forwardingScore | integer | The number of times the message was forwarded: 1 for a forwarded message, otherwise 0 |
isDeleted | boolean | The flag shows whether the message was deleted |
deletedMessageId | string | For a message - the identifier of the deletion event it was deleted by. For a deletion event record - the identifier of the deleted message |
isEdited | boolean | The flag shows whether the message was edited |
editedMessageId | string | For a message - the identifier of the last edit event. For an edit event record - the identifier of the edited message |
isRead | boolean | The flag shows whether the message was read by the instance account. only for type = incoming, except typeMessage = reactionMessage |
Response body example#
A text message#
[
{
"type": "incoming",
"idMessage": "32992354783594572492903878028689408",
"timestamp": 1766486400,
"typeMessage": "textMessage",
"chatId": "49547665464",
"chatType": "user",
"chatUsername": "@green_api",
"textMessage": "Hi!",
"senderId": "49547665464",
"senderName": "GREEN-API",
"senderUsername": "@green_api",
"senderType": "user",
"isForwarded": false,
"forwardingScore": 0,
"deletedMessageId": "",
"editedMessageId": "",
"isEdited": false,
"isDeleted": false
}
]
A message with an image#
[
{
"type": "outgoing",
"idMessage": "32992354910263051384774140624896000",
"timestamp": 1766486460,
"typeMessage": "imageMessage",
"chatId": "49547665464",
"chatType": "user",
"chatUsername": "@green_api",
"downloadUrl": "https://scontent.cdninstagram.com/v/photo.jpg",
"caption": "",
"fileName": "photo.jpg",
"jpegThumbnail": "",
"isAnimated": false,
"mimeType": "image/jpeg",
"statusMessage": "read",
"sendByApi": true,
"isForwarded": false,
"forwardingScore": 0,
"deletedMessageId": "",
"editedMessageId": "",
"isEdited": false,
"isDeleted": false
}
]
A reply to a message#
[
{
"type": "outgoing",
"idMessage": "32992354783594572492903878028689500",
"timestamp": 1766486520,
"typeMessage": "textMessage",
"chatId": "49547665464",
"chatType": "user",
"chatUsername": "@green_api",
"textMessage": "I am replying to your message",
"quotedMessage": {
"stanzaId": "32992354783594572492903878028689408",
"participant": "49547665464"
},
"statusMessage": "delivered",
"sendByApi": true,
"isForwarded": false,
"forwardingScore": 0,
"deletedMessageId": "",
"editedMessageId": "",
"isEdited": false,
"isDeleted": false
}
]
A message with a post#
[
{
"type": "incoming",
"idMessage": "32992354783594572492903878028690500",
"timestamp": 1766486540,
"typeMessage": "sharedMessage",
"chatId": "49547665464",
"chatType": "user",
"chatUsername": "@green_api",
"sharedType": "reel",
"sharedUrl": "https://www.instagram.com/reel/DdQfRC2xJuV/",
"authorId": "49547665464",
"authorName": "GREEN-API",
"authorUsername": "@green_api",
"downloadUrl": "https://scontent.cdninstagram.com/o1/v/t2/f2/m86/AQNxlSk3nZ.mp4?oe=1",
"caption": "The caption of the post",
"fileName": "AQNxlSk3nZ.mp4",
"jpegThumbnail": "",
"mimeType": "video/mp4",
"isAnimated": false,
"isForwarded": false,
"forwardingScore": 0,
"senderId": "49547665464",
"senderName": "GREEN-API",
"senderUsername": "@green_api",
"senderType": "user",
"deletedMessageId": "",
"editedMessageId": "",
"isEdited": false,
"isDeleted": false
}
]
A message with a profile card#
[
{
"type": "incoming",
"idMessage": "32992354783594572492903878028690600",
"timestamp": 1766486580,
"typeMessage": "contactMessage",
"chatId": "49547665464",
"chatType": "user",
"chatUsername": "@green_api",
"contactMessageData": {
"chatId": "25025320",
"urlAvatar": "https://scontent.cdninstagram.com/v/avatar.jpg",
"displayName": "Instagram",
"username": "@instagram",
"phoneNumber": "",
"forwardingScore": 0,
"isForwarded": false
},
"senderId": "49547665464",
"senderName": "GREEN-API",
"senderUsername": "@green_api",
"senderType": "user",
"deletedMessageId": "",
"editedMessageId": "",
"isEdited": false,
"isDeleted": false
}
]
A message with a location#
[
{
"type": "incoming",
"idMessage": "32992354783594572492903878028690100",
"timestamp": 1766486640,
"typeMessage": "locationMessage",
"chatId": "49547665464",
"chatType": "user",
"chatUsername": "@green_api",
"location": {
"nameLocation": "Astana Arena",
"address": "Turan Ave 48, Astana 020000",
"jpegThumbnail": "",
"latitude": 51.1035035,
"longitude": 71.3996933,
"forwardingScore": 0,
"isForwarded": false
},
"senderId": "49547665464",
"senderName": "GREEN-API",
"senderUsername": "@green_api",
"senderType": "user",
"deletedMessageId": "",
"editedMessageId": "",
"isEdited": false,
"isDeleted": false
}
]
A message with a poll#
[
{
"type": "incoming",
"idMessage": "32992354783594572492903878028690200",
"timestamp": 1766486680,
"typeMessage": "pollMessage",
"chatId": "340282366841710300949128174631143137232",
"chatType": "group",
"chatUsername": "",
"pollMessageData": {
"name": "What time shall we meet?",
"options": [
{
"optionName": "10:00"
},
{
"optionName": "14:00"
}
],
"multipleAnswers": false
},
"senderId": "49547665464",
"senderName": "GREEN-API",
"senderUsername": "@green_api",
"senderType": "user",
"deletedMessageId": "",
"editedMessageId": "",
"isEdited": false,
"isDeleted": false
}
]
An edited message#
[
{
"type": "outgoing",
"idMessage": "32992354783594572492903878028689700",
"timestamp": 1766486560,
"typeMessage": "textMessage",
"chatId": "49547665464",
"chatType": "user",
"chatUsername": "@green_api",
"textMessage": "The edited message",
"statusMessage": "read",
"sendByApi": true,
"isEdited": true,
"editedMessageId": "32992354783594572492903915434680320",
"isForwarded": false,
"forwardingScore": 0,
"deletedMessageId": "",
"isDeleted": false
}
]
A deletion event#
[
{
"type": "outgoing",
"idMessage": "32992354783594572492903939751251968",
"timestamp": 1766486600,
"typeMessage": "deletedMessage",
"chatId": "49547665464",
"chatType": "user",
"chatUsername": "@green_api",
"statusMessage": "delivered",
"sendByApi": true,
"isDeleted": true,
"deletedMessageId": "32992354783594572492903890371584000",
"editedMessageId": "",
"isEdited": false
}
]
Polls in the journal
The poll itself gets into the journal - the question and the answer options as of the moment it was created. The votes for the options arrive only as the pollUpdateMessage notification: there are no records of them in the journals, and the votes are not updated in the record of the poll.
Edits and deletions in the history
An edited message stays in the history under its own identifier: textMessage is the text after the edit, isEdited is true, and editedMessageId is the identifier of the last edit event. The edit records themselves do not get into the history, and deleted messages are hidden from it - only the deletion event record remains.
You can get an edit record or a deleted message by its identifier with the GetMessage method.
GetChatHistory errors#
For a list of errors common to all methods, refer to the Common errors section
| HTTP code | Error ID | Description |
|---|---|---|
| 400 | Bad Request Validation failed | Validation error |
Request examples#
import requests
url = "{{apiUrl}}/waInstance{{idInstance}}/getChatHistory/{{apiTokenInstance}}"
payload = {"chatId": "49547665464"}
headers = {'Content-Type': 'application/json'}
response = requests.post(url, json=payload, headers=headers)
print(response.text.encode('utf8'))
curl --location '{{apiUrl}}/waInstance{{idInstance}}/getChatHistory/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{"chatId": "49547665464"}'