Skip to content

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 {{apiUrl}}/waInstance{{idInstance}}/lastIncomingMessages/{{apiTokenInstance}}?minutes={{minutes_count}}

For idInstance, apiTokenInstance and apiUrl 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
type string Message type, incoming - incoming message
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
stickerMessage - sticker message
reactionMessage - reaction message
locationMessage - location message
contactMessage - contact message
extendedTextMessage - link and preview message
pollMessage - poll message
pollUpdateMessage - poll message update
incomingBlock - notification about adding a chat to the list of blocked contacts Notification is temporarily not working
quotedMessage - quoted message
buttonsMessage - buttons message (The method is temporarily not working)
templateMessage - template buttons message (The method is temporarily not working)
listMessage - list button message (The method is temporarily not working)
buttonsResponseMessage - buttons response (The method is temporarily not working)
templateButtonsReplyMessage - template buttons response (The method is temporarily not working)
listResponseMessage - list response (The method is temporarily not working)
chatId string Chat Id, where the message has been received. By default, takes the value 10000000000@c.us, if typeMessage = incomingBlock
senderId string Message sender Id. By default, takes the value 10000000000@c.us, if typeMessage = incomingBlock
senderName string Message sender name
senderContactName string Message sender name according to the contact list of the current account
isForwarded boolean The flag indicates whether the message is forwarded
forwardingScore integer Number of message forwards
textMessage string Text message, if typeMessage=textMessage/extendedTextMessage
downloadUrl string Link to download a file, if if typeMessage = imageMessage/videoMessage /documentMessage/audioMessage/stickerMessage
caption string File caption, if typeMessage = imageMessage/videoMessage /documentMessage/audioMessage/stickerMessage
fileName string File name, if typeMessage = imageMessage/videoMessage /documentMessage/audioMessage/stickerMessage. The field is filled in correctly only for typeMessage = documentMessage, in other cases the file name is generated automatically
jpegThumbnail string base64-coded image preview, if typeMessage = imageMessage /videoMessage/documentMessage/audioMessage/stickerMessage
mimeType string File type according to the Media Types, if typeMessage = imageMessage /videoMessage/documentMessage/audioMessage/stickerMessage
isAnimated boolean The flag indicates whether the file is animated, if typeMessage = imageMessage/videoMessage/documentMessage/audioMessage/stickerMessage
chatState string Chat state, if typeMessage = incomingBlock
location object Location structure object, if typeMessage = locationMessage
contact object Contact structure object, if typeMessage = contactMessage
extendedTextMessage object Text message object (advanced), if typeMessage = extendedTextMessage/quotedMessage
extendedTextMessageData object Reaction message data object, if typeMessage = reactionMessage
pollMessageData object Poll data structure object, if typeMessage = pollMessage/pollUpdateMessage
quotedMessage object Quoted message data object, if typeMessage = quotedMessage/reactionMessage

Response body example#

[
    {
        "type": "incoming",
        "idMessage": "9DB14F14A253D33F4A9CD84123456789",
        "timestamp": 1706522263,
        "typeMessage": "textMessage",
        "chatId": "120363153000000000@g.us",
        "textMessage": "Hi",
        "senderId": "70000000012@c.us",
        "senderName": "Rachel",
        "senderContactName": "Rachel 2"
    },
    {
        "type": "incoming",
        "idMessage": "EAAE5A5CD000000000",
        "timestamp": 1706601620,
        "typeMessage": "imageMessage",  //"videoMessage"/`documentMessage`/`audioMessage`/`stickerMessage`
        "chatId": "120363153000000000@g.us",
        "downloadUrl": "https://api.greenwaba.com/waInstance1234/downloadFile/EA1BD1AE042DC4F3609867126309D67C.jpg",
        "caption": "What do you think?",
        "fileName": "03963bac-6020-423c-80df-1aa123456789.jpg",
        "jpegThumbnail": "/9j/4AAQSkZJ/aAAgBAwEBPwCVYw//xAApEAACAx/2kOVh/VKAoAH/leFhX//+AAMA/9k=",
        "mimeType": "image/jpeg",
        "isAnimated": false,
        "isForwarded": true,
        "forwardingScore": 1,
        "senderId": "70000000012@c.us",
        "senderName": "Rachel",
        "senderContactName": "Rachel 2"
    },
    {
        "type": "incoming",
        "idMessage": "3A1EBA0F23004BD415BB",
        "timestamp": 1706601621,
        "typeMessage": "reactionMessage",
        "chatId": "70000000012@c.us",
        "extendedTextMessageData": {
            "text": "😄"
        },
        "quotedMessage": {
            "stanzaId": "B4D7D8A1A7D887D5580F000000000000",
            "participant": "70000000012@c.us",
        },
        "senderId": "70000000013@c.us",
        "senderName": "Rachel",
        "senderContactName": "Rachel 2"
    },
    {
        "type": "incoming",
        "idMessage": "3A8427EF85F000000000",
        "timestamp": 1706674611,
        "typeMessage": "locationMessage",
        "chatId": "70000000012@c.us",
        "location": {
            "nameLocation": "Cafe",
            "address": "Astana",
            "jpegThumbnail": "/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRX",
            "latitude": 51.1280000000000,
            "longitude": 71.4307620000000,
            "forwardingScore": 0,
            "isForwarded": false
        },
        "senderId": "70000000012@c.us",
        "senderName": "Rachel",
        "senderContactName": "Rachel 2"
    },
    {
        "type": "incoming",
        "idMessage": "3AA2C1D83560000000000",
        "timestamp": 1706675513,
        "typeMessage": "contactMessage",
        "chatId": "70000000012@c.us",
        "contact": {
            "displayName": "Anastasia",
            "vcard": "BEGIN:VCARD\nVERSION:3.0\nN:;Anastasia;;;\nFN:Anastasia\nTEL;type=CELL;type=VOICE;waid=70000000013:+7 000 000-00-13\nEND:VCARD",
            "forwardingScore": 0,
            "isForwarded": false
        },
        "senderId": "70000000012@c.us",
        "senderName": "Rachel",
        "senderContactName": "Rachel 2"
    },
    {
        "type": "incoming",
        "idMessage": "3A66D7F0B50000000000",
        "timestamp": 1706675928,
        "typeMessage": "extendedTextMessage",
        "chatId": "70000000012@c.us",
        "textMessage": "Hqhqhhqh\nhttps://greenwaba.com",
        "extendedTextMessage": {
            "text": "Hqhqhhqh\nhttps://greenwaba.com",
            "description": "GreenWaba: WhatsApp API on any language PHP, JavaScript, 1C, Python, Java, C#, VBA etc.",
            "title": "GreenWaba: send and receive WhatsApp messages",
            "previewType": "None",
            "jpegThumbnail": "/9j/4AAQSkZJRgABAQAAAQABZ",
            "forwardingScore": 0,
            "isForwarded": false
        },
        "senderId": "70000000012@c.us",
        "senderName": "Rachel",
        "senderContactName": "Rachel 2"
    },
    {
        "type": "incoming",
        "idMessage": "3A71511C3A0000000000",
        "timestamp": 1706676278,
        "typeMessage": "pollMessage",
        "chatId": "70000000012@c.us",
        "pollMessageData": {
            "name": "Choose your favorite color",
            "options": [
                {
                    "optionName": "Red"
                },
                {
                    "optionName": "Green"
                }
            ],
            "multipleAnswers": true
        },
        "senderId": "70000000012@c.us",
        "senderName": "Rachel",
        "senderContactName": "Rachel 2"
    },
    {
        "type": "incoming",
        "idMessage": "3A0493ED90000000000000",
        "timestamp": 1706676447,
        "typeMessage": "pollUpdateMessage",
        "chatId": "70000000012@c.us",
        "pollMessageData": {
            "name": "Where will we go?",
            "stanzaId": "46618B98B3B9DF50F123456789123456",
            "votes": [
                {
                    "optionName": "Beach",
                    "optionVoters": [
                        "70000000012@c.us"
                    ]
                },
                {
                    "optionName": "Mountains",
                    "optionVoters": []
                }
            ],
            "multipleAnswers": true
        },
        "senderId": "70000000012@c.us",
        "senderName": "Rachel",
        "senderContactName": "Rachel 2"
    },
    {
        "type": "incoming",
        "typeMessage": "incomingBlock",
        "timestamp": 1706676650,
        "chatId": "10000000000@c.us",
        "senderId": "10000000000@c.us",
        "chatState": "blocked"
    },
    {
        "type": "incoming",
        "idMessage": "3AB0EB938BA0000000000",
        "timestamp": 1706677013,
        "typeMessage": "quotedMessage",
        "chatId": "70000000012@c.us",
        "extendedTextMessage": {
            "text": "For the beach",
            "stanzaId": "46618B98B3B9DF50F123456789123456",
            "participant": "70000000012@c.us"
        },
        "quotedMessage": {
            "stanzaId": "46618B98B3B9DF50F123456789123456",
            "participant": "70000000012@c.us",
            "typeMessage": "pollMessage",
            "pollMessageData": {
                "name": "Where will we go?",
                "options": [],
                "multipleAnswers": true
            }
        },
        "senderId": "70000000012@c.us",
        "senderName": "Rachel",
        "senderContactName": "Rachel 2"
    },
    {
        "type": "incoming",
        "idMessage": "3A70B27A6020000000000",
        "timestamp": 1706677254,
        "typeMessage": "quotedMessage",
        "chatId": "70000000012@c.us",
        "extendedTextMessage": {
            "text": "Great!",
            "stanzaId": "EAAE5A5CD000000000",
            "participant": "70000000012@c.us"
        },
        "quotedMessage": {
            "stanzaId": "EAAE5A5CD000000000",
            "participant": "70000000012@c.us",
            "typeMessage": "imageMessage", //"videoMessage"/`documentMessage`/`audioMessage`/`stickerMessage`
            "downloadUrl": "",
            "caption": "",
            "fileName": "",
            "jpegThumbnail": "/9j/4AAQSkZJRgABAQAAA=",
            "mimeType": "image/jpeg",
            "isAnimated": false,
            "isForwarded": false,
            "forwardingScore": 0
        },
        "senderId": "70000000012@c.us",
        "senderName": "Rachel",
        "senderContactName": "Rachel 2"
    }
]

LastIncomingMessages errors#

For a list of errors common to all methods, refer to Common errors section

Request examples#

import requests

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

payload = {}
headers= {}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
curl --location '{{apiUrl}}/waInstance{{idInstance}}/lastIncomingMessages/{{apiTokenInstance}}?minutes=3240'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .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({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/lastIncomingMessages/")
    .append({{apiTokenInstance}});

var response = Unirest.get(requestUrl.toString())
    .header("Content-Type", "application/json")
    .asString();

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

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

    Set http = CreateObject("MSXML2.XMLHTTP")

    http.Open "GET", url, False
    http.send

    response = http.responseText

    Debug.Print response

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

    Set http = Nothing
End Sub