Loader

Basic commands

This section outlines the available WhatsApp Enterprise API functions to send and receive messages successfully.

The base URL for all API call strings is: https://platform.clickatell.com

You can send the following message types via the REST API:

  1. Text message – plain text, rich text and URL support
  2. Templated messages (also known as Highly Structured Messages [HSM])
  3. Media Messages

Note: Businesses cannot initiate non-template messages to the end-users unless it is within the Customer Care window. Please review the latest Business Messaging Guide for more details on the various conversation types before implementing the below API calls.


Send Message API

Plain text

This command allows you to send one or more WhatsApp messages. The server will respond with a unique identifier for each message. The Clickatell platform then asynchronously targets the callback URL with status updates.

Request headers:

POST /wa/messages
Content-Type: application/json
Authorization: MC2 integration API KEY


JSON Request

{
 "messages": [
  {
   "to""27999000001",
   "content""Here is an example message",
   "clientMessageId""2993b6b548000a80989a20549e7558a5"
  }
 ]
}


Response

{
 "error"null,
 "messages": [
   {
    "messageId""3a89680503414383af44dcd0e4e5f184",
    "clientMessageId""2993b6b548000a80989a20549e7558a5",
    "accepted"true,
    "to""27999000001",
    "error"null
  }
 ]
}

Rich formatted text

Clickatell supports the following text formatting options when sending messages from business to end-user.

Formatting
Symbol
Example
Bold Asterisk ( * ) This text is *bold*
Italics Underscore ( _ ) My first _italic_ message
Strikethrough Tilde ( ~ ) This is a ~strikethrough~ message
Code Three backquote/backtick ( “` ) “`print ‘Hello World’;“`

URL preview formatted text

This flag allows you to enable an URL preview of the first URL in your message on the recipient handset. WhatsApp by default recognizes an URL and makes it clickable within the application.

Please ensure the URL begins with http:// or https:// in the message content body.

Request headers:

POST /wa/messages
Content-Type: application/json
Authorization: MC2 integration API KEY


JSON Request

{
 "messages": [
  {
   "to""27999000001",
   "content""Check out http://www.clickatell.com to learn more about our latest products and services",
   "previewFirstUrl""True",
   "clientMessageId""2993b6b548000a80989a20549e7558a5"
  }
 ]
}


Response

{
 "error"null,
 "messages": [
  {
   "messageId""3a89680503414383af44dcd0e4e5f184",
   "clientMessageId""2993b6b548000a80989a20549e7558a5",
   "accepted"true,
   "to""27999000001",
   "error"null
  }
 ]
}

Template messaging

For the delivery of outbound transactional messages or re-engagement messages, a templated message format is required. This message is defined as a Highly Structured Message (HSM) message type. All the same text formatting will apply to templated messages as well.

Please ensure the template reference is preapproved for your business before use.

When sending a template message, you need to specify the template reference and associated parameter values of your template within the HSM array. Please note that the parameters in your template are in a sequential order beginning at {{1}}. Template parameters cannot have new-line/tab characters or more than four consecutive spaces or will be rejected by the WhatsApp client.

Sample template message: Hello {{1}}. This is a demo welcome message from {{2}}
Sample template reference: welcome_notification_demo


Request headers:

POST /wa/messages
Content-Type: application/json
Authorization: MC2 integration API KEY


JSON Request

{
 "messages": [
  {
   "to""27999000001",
   "hsm": {
    "template""welcome_notification_demo",
    "parameters": {"1""John""2""Clickatell"}
   }
  }
 ]
}


Response

{
 "error"null,
 "messages": [
  {
   "messageId""3a89680503414383af44dcd0e4e5f184",
   "clientMessageId"null,
   "accepted"true,
   "to""27999000001",
   "error"null
  }
 ]
}

The following message will be received on the phone:

Hello John. This is a demo welcome message from Clickatell
 
Media messages

This command allows you to send messages containing images, documents or audio files to your consumer. Sending video in messages is not supported. Clickatell supports media sending by byte streams where the message content will be set to the base64-encoded file content value and the content-type correctly set to describe the data contained in the message body. If set incorrectly, the message API may not be able to process the content appropriately and the delivery may fail. If left blank, the message will be considered as text message type by default and processed accordingly. 

The caption parameter is optional and can be used to reference or name the media content being sent.

Request headers:

POST /wa/messages
Content-Type: application/json
Authorization: MC2 integration API KEY


JSON Request

{
 "messages": [
  {
   "to""27999000001",
   "contentType""image/png",
   "content""/9j/4AAQSkZJRgABAQEASABIAAD/2w ... SDayT2Nha/OIUS3FhlyHzB8ic6ctekf/9k=",
   "caption""First Image File"
  }
 ]
}


Response

{
 "error"null,
 "messages": [
  {
   "messageId""3a89680503414383af44dcd0e4e5f184",
   "clientMessageId"null,
   "accepted"true,
   "to""27999000001",
   "error"null
  }
 ]
}

 

Some of the popular supported media file types and their associated content-types for reference:

Media
Supported file types
Associated content-type
document PDF, DOC(X), PPT(X), XLS(X) application/pdf
application/msword
application/vnd.ms-powerpoint
application/vnd.ms-excel
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/vnd.openxmlformats-officedocument.presentationml.presentation
application/vnd.openxmlformats-officedocument.wordprocessingml.document
image JPG, JPEG, PNG image/jpg
image/jpeg
image/png
audio AAC, MP4, MP3, AMR, OPUS audio/aac
audio/mp4
audio/mp3
audio/amr
audio/ogg
 
Encrypted message content

This command allows you to send encrypted message content using the Send Message API. The encryptionKey parameter will indicate to the API that the message content being transmitted is encrypted. The encryptionKey must be the base64 encoded ciphertext blob with which the message content was encrypted.

Message content encryption will be supported for text messages, templated messages and all supported media file types.


Encrypted text message example

Request headers:

POST /wa/messages
Content-Type: application/json
Authorization: MC2 integration API KEY


JSON Request

{
 "messages": [
  "to""27999000001",
   "content""gv2pYQ5T0MjTax50hPLHIqnSSIb … HXFPPeWcz6tIzgZg1gxZ6QQ7BfczEKNc=",
   "clientMessageId""2993b6b548000a80989a20549e7558a5",
  }
 ],
"encryptionKey":"AQIDAHh6Ji8OpMJqM/F8 … MyoTOwK1KkI1z9rI+LY7bNLFksXmbwnOgftmgoodQ=="
}


Encrypted template message example

For templated messages, you can encrypt the values of the parameters within the API call as below. The remaining structure of the message must be left unencrypted to facilitate structure validation on API acceptance.

JSON Request

{
 "messages": [
  {
   "to""27999000001",
   "hsm": {
    "template"" welcome_notification_demo",
    "parameters": {
     "1":"gv2pYQ5T0MjTax5 … cz6tIzgZg1gxZ6QQ7BfczEKNc=",
     "2":" gv2pYQ5T0MjTax ... nyKi9PtqBPUtc7HXFPPeWcz6tIzgZg1gxZ6QQ7BfczEKNc="
    }
   }
  }
 ],
"encryptionKey":"AQIDAHh6Ji8OpMJqM/ … ffKt3dLlMyoTOwK1KkI1z9rI+LY7bNLFksXmbwnOgftmgoodQ=="
}


Encrypted media message example

Encrypted media messages require an additional parameter, sha265Hash. This is a hash of the file content that is being submitted before it is encrypted. The hash is used to verify that the media was decrypted successfully, before submission to WhatsApp Enterprise API. The hash value itself is sent unencrypted.

Request headers:

POST /wa/messages
Content-Type: application/json
Authorization: MC2 integration API KEY


JSON Request

{
 "messages": [
  {
   "to""27999000001",
   "contentType""image/png",
   "content""/9j/4AAQSkZJRgABAQEASABIAAD/2w ... SDayT2Nha/OIUS3FhlyHzB8ic6ctekf/9k=",
   "caption""gv2pYQ5T0MjTax5 … cz6tIzgZg1gxZ6QQ7BfczEKNc=",
   "encryptionKey""OeVmffKt3dLlMyoTOw … rI+LY7bNLFksXmbwnOgftmgoodQ==",
   "sha256Hash""529fd5482f43db39992a894bbe4216f51a4d724131a97b93cc5589433b545820",
  }
 ]
}


Response

{
 "error"null,
 "messages": [
  {
   "messageId""3a89680503414383af44dcd0e4e5f184",
   "clientMessageId"null,
   "accepted"true,
   "to""27999000001",
   "error"null
  }
 ]
}
 
General Callback API note:

Forward Compatibility

While the basic callback parameters will remain constant:

{
 "integrationId":"string", 
 "integrationName":"string",
 "messageId": "string"
}

 

there are frequent additions to channels including new features and message types, Clickatell will be adding these to the callbacks as they become available. Customers are required to implement callback processing in such a way that additional parameters in the JSON structure do not break callback processing in the customer system.


Message status callback API

Clickatell will asynchronously send a callback to your application on the status update per message when received from WhatsApp. The callbacks may arrive out of order, but a timestamp is included with each callback for your reference.


Status callback example

Below is a standard callback sample when the message has been read by recipient:

POST Request

{
 "integrationId""fa8090815f05d5ed015f0b5b56080cd2",
 "integrationName""My integration",
 "timestamp"1506607698860,
 "statusCode"4,
 "status""RECEIVED_BY_RECIPIENT",
 "messageId""3a89680503414383af44dcd0e4e5f184",
 "clientMessageId""2993b6b548000a80989a20549e7558a5"
}

Message status descriptions

The following message statuses are generated after the Clickatell platform has accepted the message for delivery.

Status code
Status
Status detail
1001 QUEUED Message accepted by MC2
1002 QUEUED Message accepted by MC2
1004 VOLUME_LIMIT_EXCEED MONTHLY_QUOTA_EXCEED
1005 VOLUME_LIMIT_EXCEED DAILY_QUOTA_EXCEED
1006 EMULATED EMULATED
1 UNKNOWN Unknown status
2 QUEUED Message is queued for delivery
3 DELIVERED_TO_GATEWAY Message has been submitted to WhatsApp server (one checkmark on handset).
4 RECEIVED_BY_RECIPIENT Message delivered to recipient (two checkmarks).
27 READ Message read by recipient (two blue checkmarks).
7 ERROR_DELIVERING Message failed to send.
9 ERROR_DELIVERING WhatsApp accepted the message, but could not deliver the message.
28 UNKNOWN_USER The MSISDN is not on the WhatsApp network.
30 ERROR_WITH_MESSAGE Media not found.
31 ERROR_WITH_MESSAGE Media size error.
32 ERROR_WITH_MESSAGE Media checksum failure.
33 ERROR_WITH_MESSAGE The media file upload was rejected by the WhatsApp network.
34 ERROR_WITH_MESSAGE Metadata for the media file was not found or does not match the message request.
40 ERROR_WITH_MESSAGE Security access denied.
41 ERROR_WITH_MESSAGE Invalid content.
2000 ERROR_DELIVERING Upload of media file is failed.
2001 EXPIRED Upload of media file is expired.

Receive message callback API

Clickatell will asynchronously send a callback to your application with the details of any messages that were received from the WhatsApp channel (incoming messages sent from the end user’s mobile phone to your business account). Note that the message in the callbacks is independent of the original sequence of messages sent. The callback will return the incoming messages as received with a timestamp generated by the WhatsApp client for your reference. The timestamp will indicate when the message was processed by WhatsApp.


Receive message callback example

Below is a standard callback sample that is generated when an incoming message has been received by the platform:

POST Request

{
 "integrationId""ff8080815f05d5ed015f0b5b56080cd2",
 "integrationName""My WhatsApp Production Integration",
 "content""Received Message Sample",
 "messageId""ff8080815f772074015f77d65dce096d",
 "relatedMessageId"null,
 "from""27999000001",
 "profileName": "Name as setup on device WhatsApp Client",
 "timestamp"1509544054
}
 

Reply message callback example

End-users can respond to a specific message in WhatsApp. For the business to understand the context of a message reply, we include the relatedMessageId field. It will only appear for message replies and will contain the unique messageId related to the message the reply was to. No other fields are changed.

POST Request

{
 "integrationId""ff8080815f05d5ed015f0b5b56080cd2",
 "integrationName""My WhatsApp Production Integration",
 "content""Message Reply Sample",
 "messageId""ff8080815f772074015f77d65dce096d",
 "relatedMessageId""bc96838ee1334877806461ac577680ed",
 "from""27999000001",
 "profileName": "Name as setup on device WhatsApp Client",
 "timestamp"1509544054
}

Media message callback example

When a media message is received from the end-user, the platform will convert the media object into a base64 encoded string as the message content. The media message callback will also contain additional information like content-type and caption that identifies the media object type.

POST Request

{
 "integrationId""ff8080815f05d5ed015f0b5b56080cd2",
 "integrationName""My WhatsApp Production Integration",
 "content""/9j/4AAQSkZJRgABAQAAAQABAAD ... AKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/Z",
 "contentType""image/jpeg",
 "caption""My First Image",
 "messageId""ff8080815f772074015f77d65dce096d",
 "relatedMessageId"null,
 "from""27999000001",
 "profileName": "Name as setup on device WhatsApp Client",
 "timestamp"1509544054
}

Location message callback example

End-users can share their current location with the business from within the WhatsApp application. The business will receive the location information as shown below:

POST Request

{
 "integrationId""ff808081622a798a01624ddd386b4b9d",
 "integrationName""My WhatsApp Production Integration",
 "messageId""ff808081633ebe590163650ab8057086",
 "relatedMessageId"null,
 "locationAddress"" 900 Island Dr #202, Redwood City, Redwood City, CA, 94065",
 "locationName""Clickatell",
 "latitute"" 37.536033630371094",
 "longitude""-122.25885772705078",
 "from""27999000001",
 "profileName": "Name as setup on device WhatsApp Client",
 "timestamp"1526408588
}

Callbacks with encrypted content

If the content of a received message is encrypted, the callback will contain the encryptionKey parameter to be used for decrypting the message content. Media message callbacks will also have the sha256Hash parameter to be used to validate that decryption was done correctly in the customer system. Callbacks for the following message types support content encryption: plain text, template and media.

Sample encrypted text message callback information as shown below:

POST Request

{
 "integrationId""ff808081622a798a01624ddd386b4b9d",
 "integrationName""My WhatsApp Production Integration",
 "messageId""ff80808162b9ab0d0162daad668d07d",
 "content""otIIfcVc282HHnFQ/rceyuYTuOQuWyat6fgYqGsB3as= ",
 "from""27999000001",
 "profileName": "otIIfcVc282HHnF........OQuWyat6fgYqGsB3as=",
 "timestamp"1509544054,
  "encryptionKey""AQIDAHid+vQ9ckFWfI2iv/AVBpH+PJEm….KOHwqJ8v7BekfSlHgEL4iE9MTkQ=="
}


Sample encrypted media message callback
 information as shown below:

POST Request

{
 "integrationId""ff8080815f05d5ed015f0b5b56080cd2",
 "integrationName""My WhatsApp Production Integration",
 "content""/9j/4AAQSkZJRgABAQAAAQABAAD ... AKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/Z",
 "contentType""image/jpeg",
 "caption"" otIIfcVc282HHnFQ/rceyuYTuOQuWyat6fgYqGsB3as= ",
 "messageId""hg6080815f772074015f77d65dce3456",
 "relatedMessageId"null,
 "from""27999000001",
 "profileName": "otIIfcVc282HHnF........OQuWyat6fgYqGsB3as=",
 "timestamp"1509544054,
 "encryptionKey""AQIDAHid+vQ9ckFWfI2iv/AVBpH+PJEm….KOHwqJ8v7BekfSlHgEL4iE9MTkQ==",
 "sha256Hash""529fd5482f43db39992a894bbe4216f51a4d724131a97b93cc5589433b545820",
}


Sample encrypted location message callback
 information as shown below:

POST Request

{
 "integrationId""ff8080815f05d5ed015f0b5b56080cd2",
 "integrationName""My WhatsApp Production Integration",
 "locationAddress""6oqpN5WHYyKw6XZaZH4sJndi0s/bnTlnoP8foN4pLcY=",
 "locationName""7KLE+SN3T7qt2s2EhKk4Itu5E0SPWK2j32sFUMxVWZk=",
 "latitude""K3wdp0aKLsmbZP42WKuECLhBCBsws0JlAbYrwVQi52A=",
 "longitude""LA4ysZwS2lkPjAGAGbv8J/9BiK9tSi4DeDnF6Q9guqQ=",
 "messageId""9fdd3f9354fe4b038af3716def353e6d",
 "relatedMessageId"null,
 "from""27999000001",
 "profileName": "otIIfcVc282HHnF........OQuWyat6fgYqGsB3as=",
 "timestamp"1537524281000,
 "encryptionKey""AQIDAHid+vQ9ckFWfI2iv/AVBpH+PJEm….KOHwqJ8v7BekfSlHgEL4iE9MTkQ=="
}

Setting a username and password on callback (optional)

It is possible to predefine a username and password for your message callbacks. This value will then be included as parameters in the body to allow for system authentication.

Did you find this information informative?

Other Resources

Ask the Community

Visit Stack Overflow to join our community of developers and find the answer you need

Contact Support

Contact our support team and one of our agents will be in touch with you to answer any questions you have