Skip to content

SendMessage#

Test Postman

The method is aimed for sending a text message to a personal or a group chat. The message will be added to the send queue. Linked device not required when sending. Messages will be kept for 24 hours in the queue until instance will be authorized. The rate at which messages are sent from the queue is managed by Message sending delay parameter.

Video instruction#

Sending a message to yourself

When sending messages to your number or to a group with one participant, status of the message will be sent (one tick).

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 Before you start section.

Request parameters#

Parameter Type Mandatory Description
chatId string Yes Chat Id
message string Yes Message text. Emoji 😃 characters supported. Requires UTF-8 encoding without BOM
quotedMessageId string No Quoted message Id. If present, the message will be sent quoting the specified chat message.
Quoting a message is only possible from the same chat to which it is sent.
To send messages from another chat, use the ForwardMessages method
linkPreview boolean No The parameter includes displaying a preview and a description of the link. Enabled by default. Accepts values: true/false

The maximum length of a text message is 20000 characters

Request body example#

Sending a message to a personal chat:

{
    "chatId": "11001234567@c.us",
    "message": "I use Green-API to send this message to you!"
}

Sending a message to a group chat:

{
    "chatId": "11001234567-1581234048@g.us",
    "message": "I use Green-API to send this message to you!"
}

Sending a quoted message:

{
    "chatId": "11001234567@с.us",
    "message": "I use Green-API to send this message to you!",
    "quotedMessageId": "361B0E63F2FDF95903B6A9C9A102F34B"
}

Response#

Response parameters#

Parameter Type Description
idMessage string Sent message Id

Response body example#

{
    "idMessage": "3EB0C767D097B7C7C030"
}

SendMessage errors#

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

HTTP code Error identifier Description
400 Bad Request
Validation failed
Validation error
400 Validation failed.
Details: 'message' length must be less than or equal to 20000 characters long
The message text must be less than or equal to 20 000 characters
500 request entity too large Json length exceeded (>100kb)

Sending with invalid Quoted message ID

If the quotedMessageId is specified incorrectly, the system will return code 200 and the id of the message, but it will not be delivered to the recipient.

Request examples#

import requests

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

payload = {
    "chatId": "11001234567@c.us",
    "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 number to send the message to (@c.us for private chats, @g.us for group chats)
$data = array(
    'chatId' => '71234567890@c.us',
    'message' => 'Hello World'
);

$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": "71234567890@c.us",
    "message": "Hello World"
}'
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 = "{\r\n\t\"chatId\": \"11001234567@c.us\",\r\n\t\"message\": \"I use Green-API to send this message to you!\"\r\n}";

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("{\r\n\t\"chatId\": \"11001234567@c.us\",\r\n\t\"message\": \"I use Green-API to send this message to you!\"\r\n}")
    .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 number to send the message to (@c.us for private chats, @g.us for group chats)
    RequestBody = "{""chatId"":""71234567890@c.us"",""message"":""Hello World""}"

    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
program sendMessage;

{$APPTYPE CONSOLE}

uses
System.SysUtils,
System.Classes, System.Net.HttpClient, System.Net.URLClient, System.Net.HttpClientComponent;

var
HttpClient: TNetHTTPClient;
RequestBody: TStringStream;
RequestHeaders: TNetHeaders;
Response: IHTTPResponse;
EndpointURL, ID_INSTANCE, API_TOKEN_INSTANCE: string;

begin
ID_INSTANCE := '110100001';
API_TOKEN_INSTANCE := 'd75b3a66374942c5b3c019c698abc2067e151558acbd451234';

EndpointURL := 'https://api.greenapi.com/waInstance' + ID_INSTANCE + '/sendMessage/' + API_TOKEN_INSTANCE;

HttpClient := TNetHTTPClient.Create(nil);
RequestBody := TStringStream.Create('{ "chatId": "71234567890@c.us", "message": "test" }', TEncoding.UTF8);
RequestHeaders := [
    TNetHeader.Create('Content-Type', 'application/json')
];

try
    Response := HTTPClient.Post(EndpointURL, RequestBody, nil, RequestHeaders);

    if Response.StatusCode = 200 then
    Writeln('[Response]: ' + Response.ContentAsString)
    else
    Writeln('[ERROR ' + IntToStr(Response.StatusCode) + ']:' + Response.StatusText + '' + Response.ContentAsString);

    readln;
except
    on E: Exception do
    Writeln(E.ClassName, ': ', E.Message);
end;

HttpClient.Free;
RequestBody.Free;

end.