Skip to content

GetChatHistory#

Test Postman

The method returns the message history of one selected chat.

The method uses limits on the request rate per second.

Request#

To get the message history, you need to execute a request at:

POST
{{apiUrl}}/waInstance{{idInstance}}/getChatHistory/{{apiTokenInstance}}

To get the apiUrl, idInstance and apiTokenInstance request parameters, refer to the Before you start section.

Request parameters#

Parameter Type Required Description
chatId string Yes Identifier of the personal or group chat whose message history you need to get
count integer No Number of messages to get. The default value is 100

Request body example#

A request for the last 10 messages:

{
  "chatId": "10000000",
  "count": 10
}

Response#

Response fields#

Field Type Description
type string Message kind:
- outgoing - an outgoing message;
- incoming - an incoming message
idMessage string Identifier of the incoming message
timestamp integer Time the message was received in UNIX format
statusMessage string Status of the outgoing message.
Only for type = outgoing.
Possible values:
- delivered - delivered
- read - read/viewed/listened to
sendByApi boolean Flag indicating sending through the API.
Only for type = outgoing
typeMessage string Message type, possible values: textMessage/imageMessage/videoMessage /documentMessage/ audioMessage/pollMessage/locationMessage
chatId string Chat identifier the message was received in.
chatType string Chat type. Possible values: "user", "group", "supergroup", "channel", "bot"
senderName string Name of the message sender.
Only for type = incoming
senderType string Sender type. Possible values: "user", "group", "supergroup", "channel", "bot".
Only for type = incoming
senderContactName string Sender name from the phone book contact list.
Only for type = incoming
isForwarded boolean Flag of a forwarded message, true/false
forwardingScore integer Number of times the message has been forwarded
textMessage string Message text, if typeMessage=textMessage
downloadUrl string Link to download the file, if typeMessage = imageMessage /videoMessage/documentMessage/audioMessage
caption string File caption, if typeMessage = imageMessage/videoMessage /documentMessage/ audioMessage
fileName string File name, if typeMessage = imageMessage/videoMessage /documentMessage / audioMessage
jpegThumbnail string Image preview in base64 encoding, if typeMessage = imageMessage/videoMessage/documentMessage , audioMessage
mimeType string File type, according to the Media Types classification, if typeMessage = imageMessage/videoMessage/documentMessage/ audioMessage
isAnimated boolean Flag of an animated file, true/false.
Present if typeMessage = imageMessage/videoMessage/documentMessage/audioMessage

Response body example#

[
  {
    "type": "outgoing",
    "idMessage": "1769676078000",
    "timestamp": 1769676078,
    "typeMessage": "textMessage",
    "chatId": "10000000",
    "chatType": "user",
    "textMessage": "I use GREEN-API to send this message!",
    "statusMessage": "delivered",
    "sendByApi": true,
    "deletedMessageId": "",
    "editedMessageId": "",
    "isEdited": false,
    "isDeleted": false
  }
]

Errors#

For the list of errors common to all methods, see the Common errors section

HTTP code Error identifier Description
400 Bad Request
Validation failed
Validation error
400 Bad Request
Validation failed.
Details: 'count' must be a number
Incorrect data type for the count field,
or the field value exceeds the maximum safe integer value

Code examples#

import requests

url = "{{apiUrl}}/waInstance{{idInstance}}/getChatHistory/{{apiTokenInstance}}"

payload = {
    "chatId": "10000000",
    "count": 100
    }

headers = {'Content-Type': 'application/json'}

response = requests.post(url, json=payload)

print(response.text.encode('utf8'))
curl --location '{{apiUrl}}/waInstance{{idInstance}}/getChatHistory/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "chatId": "10000000",
    "count": 10
}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/getChatHistory/")
    .append({{apiTokenInstance}});

var headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

var jsonBody = "{\"chatId\": \"10000000\",\"count\": 10}";

var requestEntity = new HttpEntity<>(jsonBody, headers);

var response = restTemplate.exchange(requestUrl.toString(), HttpMethod.POST, requestEntity, String.class);
System.out.println(response);
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/getChatHistory/")
    .append({{apiTokenInstance}});

var response = Unirest.post(requestUrl.toString())
    .header("Content-Type", "application/json")
    .body("{\"chatId\": \"10000000\",\"count\": 10}")
    .asString();

System.out.println(response);
Sub GetChatHistory()
    Dim url As String
    Dim RequestBody As String
    Dim http As Object
    Dim response As String

    ' The apiUrl, idInstance and apiTokenInstance values are available in console, double brackets must be removed
    url = "{{apiUrl}}/waInstance{{idInstance}}/getChatHistory/{{apiTokenInstance}}"

    ' chatId - personal or group chat identifier whose message history you want to receive, count - number of messages to receive, default value 100
    RequestBody = "{""chatId"":""10000000"",""count"":10}"

    Set http = CreateObject("MSXML2.XMLHTTP")

    With http
        .Open "POST", url, False
        .setRequestHeader "Content-Type", "application/json"
        .send RequestBody
    End With

    response = http.responseText

    Debug.Print response

    ' Outputting the answer to the desired cell
    Range("A1").Value = response

    Set http = Nothing
End Sub