Skip to content

SendMessage#

Beta version

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

The method is used to send a text message to an Instagram Direct chat.

The message will be added to the send queue. It is kept in the queue for up to 24 hours and is sent right after the instance is authorized. The rate at which messages are sent from the queue is managed by the Message sending delay parameter.

Also check out the Message sending guidelines.

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

Request#

To send a text message, you have to execute a request at:

POST
{{apiUrl}}/waInstance{{idInstance}}/sendMessage/{{apiTokenInstance}}

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

Request parameters#

Parameter Type Mandatory Description
chatId string Yes Chat identifier - the numeric identifier of an account or of a group chat, or a username with the @ prefix
message string Yes Message text.
Emoji πŸ˜ƒ characters are supported.
The maximum length of a text message is 1000 characters. Requires UTF-8 encoding without BOM.
quotedMessageId string No The identifier of the quoted message
When the parameter is filled in, the message is sent as a quote of the specified chat message.
Specify a message of the same chat
linkPreview boolean No The parameter enables the link preview and description. Enabled by default.
On an instance authorized through a browser session, the parameter has no effect: Instagram decides whether to show the preview

Request body example#

Sending a message to a personal chat by the identifier:#

{
    "chatId": "49547665464",
    "message": "I use GREEN-API to send this message to you!"
}

Sending a message by username:#

{
    "chatId": "@green_api",
    "message": "I use GREEN-API to send this message to you!"
}

Sending a message to a group chat:#

{
    "chatId": "340282366841710300949128174631143137232",
    "message": "I use GREEN-API to send this message to you!"
}

A reply to a message:#

{
    "chatId": "49547665464",
    "message": "I am replying to your message",
    "quotedMessageId": "32992354783594572492903878028689408"
}
{
    "chatId": "49547665464",
    "message": "Look at https://example.com/page",
    "linkPreview": false
}

Response#

Response parameters#

Field Type Description
idMessage string The identifier of the sent message

Response body example#

{
    "idMessage": "32992354783594572492903878028689408"
}

SendMessage errors#

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

HTTP code Error ID Description
400 Bad Request
Validation failed
Validation error
400 Validation failed. Details:
'quotedMessageId' must be the numeric message id
The quotedMessageId parameter must contain digits only
400 Validation failed. Details:
'message' length must be less than or equal to 1000 characters long
The message text is longer than 1000 characters
500 request entity too large Json length exceeded (>100kb)

Request examples#

import requests

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

payload = {
    "chatId": "49547665464",
    "message": "I use GREEN-API to send this message to you!"
}
headers = {
    'Content-Type': 'application/json'
}

response = requests.post(url, json=payload, headers=headers)

print(response.text.encode('utf8'))
<?php
//The apiUrl, idInstance and apiTokenInstance values are available in console, double brackets must be removed
$url = '{{apiUrl}}/waInstance{{idInstance}}/sendMessage/{{apiTokenInstance}}';

//chatId is the numeric account id or the nickname with the @ prefix
$data = array(
    'chatId' => '49547665464',
    'message' => 'I use GREEN-API to send this message to you!'
);

$options = array(
    'http' => array(
        'header' => "Content-Type: application/json\r\n",
        'method' => 'POST',
        'content' => json_encode($data)
    )
);

$context = stream_context_create($options);

$response = file_get_contents($url, false, $context);

echo $response;
?>
curl --location '{{apiUrl}}/waInstance{{idInstance}}/sendMessage/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "chatId": "49547665464",
    "message": "I use GREEN-API to send this message to you!"
}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/sendMessage/")
    .append({{apiTokenInstance}});

var headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

var jsonBody = """
    {
        "chatId": "49547665464",
        "message": "I use GREEN-API to send this message to you!"
    }
    """;

var requestEntity = new HttpEntity<>(jsonBody, headers);

var response = restTemplate.exchange(requestUrl.toString(), HttpMethod.POST, requestEntity, String.class);
System.out.println(response);
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/sendMessage/")
    .append({{apiTokenInstance}});

var response = Unirest.post(requestUrl.toString())
    .header("Content-Type", "application/json")
    .body("""
        {
            "chatId": "49547665464",
            "message": "I use GREEN-API to send this message to you!"
        }
        """)
    .asString();

System.out.println(response);
Sub SendMessage()
Dim URL As String
Dim RequestBody As String
Dim http As Object

' The apiUrl, idInstance and apiTokenInstance values are available in console, double brackets must be removed
URL = "{{apiUrl}}/waInstance{{idInstance}}/sendMessage/{{apiTokenInstance}}"

' chatId is the numeric account id
RequestBody = "{""chatId"":""49547665464"",""message"":""I use GREEN-API to send this message to you!""}"

Set http = CreateObject("MSXML2.XMLHTTP")

With http
    .Open "POST", URL, False
    .setRequestHeader "Content-Type", "application/json"
    .send RequestBody
End With

Set http = Nothing

End Sub

Emoji πŸ˜ƒ characters#

There are several ways to send emojis or other symbols via the API:

  1. Using hotkeys
  2. Copying and pasting
  3. Using character codes

1. Using hotkeys#

The simplest way to do this is to use the built-in emoji feature of your operating system.

To do this, place the cursor in the text field and use the hotkeys:

  • For Windows: Win + .
  • For MacOS: control + command + space

Then select the symbol of interest in the pop-up window.

Unfortunately, this method does not work everywhere.

2. Copying and pasting#

Sometimes the simplest solution is to copy emojis from a messenger, browser, or any other source.

Example: πŸ˜ƒπŸ˜ŽπŸ€―

Example of a site with emoji.

3. Using character codes#

If the field does not support emoji insertion or if the inserted emojis do not display correctly, consider using a character encoding.

To send emojis we recommend using UTF-16. To do this, you need to represent the character as a hexadecimal number or a surrogate pair, two hexadecimal numbers.

An example of a surrogate pair: \uD83D\uDE01

These numbers are in the Unicode character table.