We are sunsetting On-Premises API. Refer to our On-Premises API Sunset document for details, and to learn how to migrate to our next-generation Cloud API.

Sending Text Messages

You can use the messages node to send text messages to your customers.

Before You Start

You need to meet all the prerequisites listed in the Before You Start section of the Messages documentation.

Constraints:

  • A text message can be a max of 4096 characters long.

Step 1: Make POST Request to /messages

Once you have the WhatsApp ID for the user you want to message, use it to send a text message. Specify text in the type field.

POST /v1/messages
{
    "preview_url": false | true,
    "recipient_type": "individual",
    "to": "whatsapp-id",
    "type": "text",
    "text": {
        "body": "your-text-message-content"
    }
}

For more information on parameters, see:

If you want to format your message, see Formatting in Text Messages.

Sending URLs in Text Messages

By default, the mobile WhatsApp application recognizes URLs and makes them clickable. To include a URL preview, include "preview_url": true in the message body and make sure the URL begins with http:// or https://. A hostname is required, IP addresses are not matched.

Note that the use of preview_url here is different from Cloud API. See the Messages Cloud API documentation.

Example

{
    "preview_url": true,
    "to": "whatsapp-id",
    "text": {
        "body": "You have to check out this amazing messaging service https://www.whatsapp.com/"
     }

The majority of the time when you send a URL, whether with a preview or not, the receiver of the message will see a URL that they can click on.

URL previews are only rendered after one of the following has happened:

  1. The business has sent a message template to the user.
  2. The user initiates a conversation with a "click to chat" link.
  3. The user adds the business phone number to their address book and initiates a conversation.

Step 2: Check Your Response

A successful response includes a messages object with an ID for the newly created message.

{
  "messages": [{
    "id": "gBEGkYiEB1VXAglK1ZEqA1YKPrU"
  }]
}  

An unsuccessful response contains an error message. See Error and Status Codes for more information.