Skip to content

SendMessage#

The method is aimed for sending a text message to a personal chat. The message will be added to the send queue. Messages will be kept for 24 hours in the queue until account will be authorized.

Sending a message to yourself

When sending messages to your number, 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 idInstance, apiTokenInstance and apiUrl 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
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 GreenWaba to send this message to you!"
}

Sending a quoted message:

{
    "chatId": "11001234567@с.us",
    "message": "I use GreenWaba 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 Id Description
400 Validation failed. Details: 'message' length must be less than or equal to 20000 characters long Message text must be less than or equal to 20000 characters

Request examples#

import requests

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

payload = "{\r\n\t\"chatId\": \"11001234567@c.us\",\r\n\t\"message\": \"I use GreenWaba to send this message to you!\"\r\n}"
headers = {
'Content-Type': 'application/json'
}

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

print(response.text.encode('utf8'))
<?php
//The idInstance and apiTokenInstance values are available in your account, 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)
$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 GreenWaba 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 GreenWaba 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 idInstance and apiTokenInstance values are available in your account, 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)
    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 := `apiUrl` + '/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.