Skip to content

ReceiveNotification#

The method is aimed for receiving one incoming notification from the notifications queue.

ReceiveNotification method waits for a notification receipt for 5 sec. The method call ends with an empty response if a timeout is reached. If a notification comes to the queue within 5 seconds, the method call is completed, and the method returns the received notification.

After receiving and processing an incoming notification, you need to delete the notification from the queue. This requires you to run DeleteNotification method. After calling DeleteNotification method, the notification will be considered received and processed and will be permanently deleted from the queue. Therefore, the next call of ReceiveNotification method will return the next notification from the queue in the order in which notifications come to the queue.

Incoming notifications are stored in the queue for 24 hours.

Notifications are sent from the queue in FIFO order

Request#

To get the next incoming notification from the queue, you have to execute a request at:

GET {{APIUrl}}/waInstance{{idInstance}}/receiveNotification/{{apiTokenInstance}}?receiveTimeout={{seconds}}

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

URL request parameters#

Parameter Type Mandatory Description
receiveTimeout integer No Notification waiting timeout, takes a value from 5 to 60 seconds (default 5 seconds)

Response#

Response parameters#

Parameter Type Description
receiptId integer Receipt Id for deleting an incoming notification by DeleteNotification method
body object Incoming notification in accordance with Incoming notifications format

Response body example#

{
    "receiptId": 1234567,
    "body": {
        "typeWebhook": "incomingMessageReceived",
        "instanceData": {
            "idInstance": 1234,
            "wid": "11001234567@c.us",
            "typeInstance": "whatsapp"
        },
        "timestamp": 1588091580,
        "idMessage": "F7AEC1B7086ECDC7E6E45923F5EDB825",
        "senderData": {
            "chatId": "79001234568@c.us",
            "sender": "79001234568@c.us",
            "senderName": "Green API"
        },
        "messageData":{
            "typeMessage":"textMessage",
            "textMessageData":{
                "textMessage":"I use Green-API to send this message to you!"
            }
        }
    }
}

ReceiveNotification errors#

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

HTTP code Error Id Description
400 Parameter idInstance not an integer idInstance parameter is not specified or contains non-digit characters
400 Parameter apiTokenInstance not define apiTokenInstance is not specified

Request examples#

import requests

url = "{{APIUrl}}/waInstance{{idInstance}}/receiveNotification/{{apiTokenInstance}}"

payload = {}
headers= {}

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

print(response.text.encode('utf8'))
curl --location '{{APIUrl}}/waInstance{{idInstance}}/receiveNotification/{{apiTokenInstance}}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
    .append("https://api.greenapi.com")
    .append("/waInstance").append({{idInstance}})
    .append("/receiveNotification/")
    .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("/receiveNotification/")
    .append({{apiTokenInstance}});

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

System.out.println(response);
Sub ReceiveNotification()
    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}}/receiveNotification/{{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 

You can see the example of notifications receipt code on NodeJS in the file ReceiveNotifications