LastIncomingMessages#
The method returns the last incoming messages of the account. In the default mode the incoming messages for 24 hours are returned.
To receive the incoming message log, you need to enable the
Receive webhooks on incoming messages and files
setting using the SetSettings method or through the personal account (Messages received before enabling this setting will not be included in the incoming message log).It may take up to 5 minutes for the settings to take effect.
The appearance of messages in the log may take up to 2 minutes. Log methods should only be used for retrieving chat history. For quicker message retrieval, use the notification system.
To receive incoming messages from the phone's history, you need to enable the instance setting
Receive webhooks on incoming messages and files
using the SetSettings method or through the personal account and scan the QR code; the history will then appear in the logs.
Request#
To get incoming messages, you have to execute a request at:
GET https://api.greenapi.com/waInstance{{idInstance}}/lastIncomingMessages/{{apiTokenInstance}}
For idInstance
and apiTokenInstance
request parameters, refer to Before you start section.
URL request parameters#
Parameter | Type | Mandatory | Description |
---|---|---|---|
minutes | integer | No | time in minutes for which the messages should be displayed (default is 1440 minutes) |
Response#
Response parameters#
Array of objects with parameters:
Parameter | Type | Description |
---|---|---|
idMessage | string | Incoming message Id |
timestamp | integer | Message acceptance time in UNIX format |
typeMessage | string | Message type, possible variants: |
textMessage - text message | ||
imageMessage - image message | ||
videoMessage - video message | ||
documentMessage - document file message | ||
audioMessage - audio message | ||
locationMessage - location message | ||
contactMessage - contact message | ||
extendedTextMessage - link and preview message | ||
quotedMessage - quoted message | ||
buttonsMessage - buttons message | ||
templateMessage - template buttons message | ||
listMessage - list button message | ||
buttonsResponseMessage - buttons response | ||
templateButtonsReplyMessage - template buttons response | ||
listResponseMessage - list response | ||
chatId | string | Chat Id, where the message has been received |
senderId | string | Message sender Id |
senderName | string | Message sender name |
textMessage | string | Text message, if typeMessage =textMessage |
downloadUrl | string | Link to download a file, if typeMessage = imageMessage /videoMessage /documentMessage /audioMessage |
caption | string | File caption |
location | object | Location structure object |
contact | object | Contact structure object |
extendedTextMessage | object | Link data structure object |
quotedMessage | object | Quoted message data object. Present only if the message itself is a quote |
Parameters of location
object:
Parameter | Type | Description |
---|---|---|
nameLocation | string | Location name |
address | string | Location address |
latitude | double | Location latitude |
longitude | double | Location longitude |
jpegThumbnail | string | base64 -coded image preview |
Parameters of contact
object:
Parameter | Type | Description |
---|---|---|
displayName | string | Contact display name |
vcard | string | VCard structure (contact visit card) |
Parameters of extendedTextMessage
object:
Parameter | Type | Description |
---|---|---|
text | string | Link text |
description | string | Link description |
title | string | Link title |
previewType | string | Link preview type |
jpegThumbnail | string | base64 -coded image preview |
stanzaId | string | Quoted message ID |
participant | string | Recipient chat ID |
Response body example#
[
{
"idMessage": "DE8CFFA93B95237B077F8FA08331A0B5",
"timestamp": 1587129319,
"typeMessage": "textMessage",
"chatId": "11001234567@c.us",
"senderId": "11001234567@c.us",
"senderName": "Nikolay",
"textMessage": "Hi"
},
{
"idMessage": "EA0BD1AE042DC4F3609867126309D67C",
"timestamp": 1587147598,
"typeMessage": "imageMessage",
"chatId": "11001234567@c.us",
"senderId": "11001234567@c.us",
"senderName": "Nikolay",
"downloadUrl": "https://api.greenapi.com/waInstance1234/downloadFile/EA1BD1AE042DC4F3609867126309D67C",
"caption": "What do you think?"
},
{
"idMessage": "DE8CFFA93B95237B077F8FA08331A0B5",
"timestamp": 1587129319,
"typeMessage": "locationMessage",
"chatId": "71234567891@c.us",
"senderId": "1234567891@c.us",
"senderName": "Nikolay",
"location": {
"nameLocation": "I'm here, come",
"address": "614111, Perm",
"latitude": 53.9370129,
"longitude": 54.8728409,
"jpegThumbnail": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wB=="
}
},
{
"idMessage": "DE8CFFA93B95237B077F8FA08331A0B5",
"timestamp": 1587129319,
"typeMessage": "contactMessage",
"chatId": "1234567891@c.us",
"senderId": "71234567891@c.us",
"senderName": "Nikolay",
"contact": {
"displayName": "Victor Petrov",
"vcard": "BEGIN:VCARD\nVERSION:3.0\nN:Andreevich;Victor;;;\nFN:Victor Andreevich\nORG:Image\nTITLE:\nitem1.TEL;waid=79099291652:+7 123 456-78-91\nitem1.X-ABLabel:Mobile\nEND:VCARD"
}
},
{
"idMessage": "DE8CFFA93B95237B077F8FA08331A0B5",
"timestamp": 1587129319,
"typeMessage": "extendedTextMessage",
"chatId": "1234567891@c.us",
"senderId": "71234567891@c.us",
"senderName": "Nikolay",
"extendedTextMessage": {
"text": "https://www.youtube.com/watch?v=9lO06Zxhu8*8*",
"description": "Video clip",
"title": "Cool video clip",
"previewType": "video",
"jpegThumbnail": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wB=="
}
},
{
"idMessage": "6195B3523153621DFDFC184D3317E80D",
"timestamp": 1603182280,
"typeMessage": "quotedMessage",
"chatId": "71234567891@c.us",
"senderId": "71234567891@c.us",
"senderName": "Mine",
"textMessage": "Quote test",
"extendedTextMessage": {
"stanzaId": "3A6424373F90A939B3C8",
"participant": "71987654321@c.us"
}
}
]
LastIncomingMessages errors#
For a list of errors common to all methods, refer to Common errors section
Request examples#
import requests
url = "https://api.greenapi.com/waInstance{{idInstance}}/lastIncomingMessages/{{apiTokenInstance}}"
payload = {}
headers= {}
response = requests.request("GET", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
curl --location 'https://api.green-api.com/waInstance{{idInstance}}/lastIncomingMessages/{{apiTokenInstance}}?minutes=3240'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
.append("https://api.greenapi.com")
.append("/waInstance").append({{idInstance}})
.append("/lastIncomingMessages/")
.append({{apiTokenInstance}});
var response = restTemplate.exchange(requestUrl.toString(), HttpMethod.GET, null, String.class);
System.out.println(response);
var requestUrl = new StringBuilder();
requestUrl
.append("https://api.greenapi.com")
.append("/waInstance").append({{idInstance}})
.append("/lastIncomingMessages/")
.append({{apiTokenInstance}});
var response = Unirest.get(requestUrl.toString())
.header("Content-Type", "application/json")
.asString();
System.out.println(response);