Skip to main content

Send WhatsApp Messages Programmatically

This endpoint will let you send messages to any WhatsApp-enabled phone number using your own number connected to 2Chat.

info

Trial accounts are rate-limited to 10 requests per minute (1 request every 6 seconds). If you would like a faster throughput, please upgrade your account.

Parameters

These parameters should be sent as JSON payload in the request body.

FieldDescriptionExample values
from_numberThe number you have connected to 2Chat+595981048477
to_numberThe number you want to send your message to+5215512345432
to_group_uuidThe WhatsApp group UUID if you intend to send it to a groupWGP768beeef-2b96-4bc7-9b7f-045078568723
textThe content of the message you want to sendTest from 2Chat API
urlThe URL of the media file you want to attach to the message. This value is optional
info

You can send text and multimedia messages, including audio, video, PDFs, images, etc., both to a single person or to a WhatsApp group.

caution

If you are sending attachments using the url field, make sure the attachment is publicly accessible and is not larger than 16 MB.

If you are using Google Drive or you are not sure if the URL is publicly accessible, download it and reupload it to 2Chat to make sure it is. Learn how here.

tip

You can't use to_number and to_group_uuid in the same request. You can either send a message to a number or to a group but not at the same time.

Learn more about where to get the group's UUID here.

Invocation

curl --location --request POST 'https://api.p.2chat.io/open/whatsapp/send-message' \
--header 'X-User-API-Key: your_api_key_here' \
--header 'Content-Type: application/json' \
--data-raw '{
"to_number": "+5215512345432",
"from_number": "+595981048477",
"text": "Test from 2Chat API",
"url": "https://uploads-ssl.webflow.com/6281a9c52303343ff7c3b269/62a1648ee0273340bf38e3a9_logo-2C.svg"
}'

Results

The invocation above will send a text message along with a 2Chat logo as an attached image.

2Chat WhatsApp Message

And that same message will appear in 2Chat (and in your WhatsApp app) as sent Via API.

2Chat API interface on the web application

Response

The API will return whether it succeded or not to queue the message for sending

{
"success": true,
"batched": true
}
FieldDescription
successTrue when the request was accepted and successful
batchedTrue when the message was successfully queued for sending