Skip to content

LastIncomingMessages#

Beta version

The functionality is in beta. Features may change and may also work unstably.

The method returns the last incoming messages of the account across all the chats - no more than 100 records, from the most recent to the earlier ones.

The method uses the limits on the number of requests per second.

Request#

To get the journal of incoming messages, you have to execute a request at:

GET
{{apiUrl}}/waInstance{{idInstance}}/lastIncomingMessages/{{apiTokenInstance}}

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

Response#

Response parameters#

An array of objects with the fields:

Field Type Description
type string The kind of the message: always incoming
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
senderName string The name of the sender from the Instagram profile. If there is no name in the profile - the username without @
senderUsername string The username of the sender in the @username form
senderType string The type of the sender: user - an account, bot - the Meta AI bot
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.
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": "incoming",
        "idMessage": "32992354783594572492903878028690300",
        "timestamp": 1766486440,
        "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",
        "senderId": "49547665464",
        "senderName": "GREEN-API",
        "senderUsername": "@green_api",
        "senderType": "user",
        "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": "incoming",
        "idMessage": "32992354783594572492903902154752000",
        "timestamp": 1766486480,
        "typeMessage": "textMessage",
        "chatId": "49547665464",
        "chatType": "user",
        "chatUsername": "@green_api",
        "textMessage": "The edited message",
        "senderId": "49547665464",
        "senderName": "GREEN-API",
        "senderUsername": "@green_api",
        "senderType": "user",
        "isEdited": true,
        "editedMessageId": "32992354783594572492903952841687040",
        "isForwarded": false,
        "forwardingScore": 0,
        "deletedMessageId": "",
        "isDeleted": false
    }
]

A deletion event#

[
    {
        "type": "incoming",
        "idMessage": "32992354783594572492903964108242944",
        "timestamp": 1766486700,
        "typeMessage": "deletedMessage",
        "chatId": "49547665464",
        "chatType": "user",
        "chatUsername": "@green_api",
        "senderId": "49547665464",
        "senderName": "GREEN-API",
        "senderUsername": "@green_api",
        "senderType": "user",
        "isDeleted": true,
        "deletedMessageId": "32992354783594572492903927576354872",
        "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 journal

An edited message stays in the journal 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 journal, 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.

LastIncomingMessages errors#

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

Request examples#

import requests

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

response = requests.get(url)

print(response.text.encode('utf8'))
curl --location '{{apiUrl}}/waInstance{{idInstance}}/lastIncomingMessages/{{apiTokenInstance}}'