ReceiveNotification#
The method is intended for receiving one incoming notification from the notification queue.
The ReceiveNotification method waits for a notification for 5 seconds.
- If no notification appears in the queue within 5 seconds, the method call ends with an empty response.
- If a notification appears in the queue within 5 seconds, the method call ends and the method returns the received notification.
- If DeleteNotification was not called after receiving a notification, the next ReceiveNotification call will show the old notification until it is deleted from the queue.
The method uses limits on the request rate per second.
Request#
To receive the next incoming notification from the queue, you need to execute a request at:
GET
{{apiUrl}}/waInstance{{idInstance}}/receiveNotification/{{apiTokenInstance}}?receiveTimeout={{seconds}}
To get the apiUrl, idInstance and apiTokenInstance request parameters, refer to the Before you start section.
Request URL parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
receiveTimeout | integer | no | Notification waiting timeout, takes a value from 5 to 60 seconds (5 seconds by default) |
Response#
Response fields#
| Field | Type | Description |
|---|---|---|
receiptId | integer | Delivery identifier for deleting an incoming notification using the DeleteNotification method |
body | object | Incoming notification according to the Incoming notifications format |
Response body example#
{
"receiptId": 1234567,
"body": {
"typeWebhook": "incomingMessageReceived",
"instanceData": {
"idInstance": 410000001,
"wid": "79876543210@c.us",
"typeInstance": "telegram"
},
"timestamp": 1763115112,
"idMessage": "126543123451133331119",
"senderData": {
"chatId": "10000000",
"chatName": "Vasilisa",
"sender": "10000000",
"senderName": "Vasilisa the Wise",
"senderContactName": "Vasilisa the Wise",
"senderPhoneNumber": 79876543210
},
"messageData": {
"typeMessage": "textMessage",
"textMessageData": {
"textMessage": "Hello from Green-API!"
}
}
}
}
ReceiveNotification errors#
For the list of errors common to all methods, see the Common errors section
| HTTP code | Error identifier | Description |
|---|---|---|
| 400 | Parameter idInstance not an integer | The idInstance parameter is not set or contains non-numeric characters |
| 400 | Parameter apiTokenInstance not define | The apiTokenInstance parameter is not set |
| 400 | Message cannot be received because custom webhook url is set. Go to cabinet, clear webhook url for instance: XXXXXXXXXX and wait for about 1 minute for another attempt | The webhookUrl field is not empty. Clear the URL for instance XXXXXXXXXX and wait about 1 minute before you start requesting notifications. |
Code 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({{apiUrl}})
.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({{apiUrl}})
.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 apiUrl, idInstance and apiTokenInstance values are available in console, 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