Send a Text Template Message through WhatsApp
POST and GET Method
This API will help you create and send WhatsApp Message Templates.
Template messages are predefined messages that are used for standard communication and are designed to be reusable.
- Sign up for free
Before you get started, sign up for a Kaleyra.io account for free Create an API Key. To view the API Key and the SID, see View API Key and SID.
- Pre-requisites
Below listed are the pre-requisites for using Kalyera WhatsApp API’s
- A WhatsApp business number.
- An associated profile with the business number.
- A WhatsApp verified and approved profile.
For more details, read what WhatsApp has to say about creating a business account.
Read Message Templates for any questions you may have about creating templates.
- Send a Text Template Message
You can use the below API’s to send a template message via WhatsApp account
Request Format - POST
curl -X POST "https://api.kaleyra.io/v1/<SID>/messages" \
-H "api-key: <API_KEY>" \
-d "from=<FROM_NUMBER>" \
-d "to=<TO_NUMBER>" \
-d "type=<MESSAGE_TYPE>" \
-d "channel=<CHANNEL_NAME>" \
-d "template_name=<TEMPLATE_NAME>" \
-d "params=<TEMPLATE_PARAMETERS>" \
-d "lang_code=<LANGUAGE_CODE>" \
-d "callback_url=<CALLBACK_URL>"
Request Format - GET
curl --request GET 'https://api.kaleyra.io/v1/<SID>/messages?channel=<CHANNEL_NAME>&to=<TO_NUMBER>&from=<FROM_NUMBER>&type=<MESSAGE_TYPE>&template_name=<TEMPLATE_NAME>¶ms=<TEMPLATE_PARAMETERS>&lang_code=<LANGUAGE_CODE>&callback_url=<CALLBACK_URL>'
--header 'api-key: <API_KEY>'
NOTE
Replace the placeholders above with relevant values as mentioned below.
Replace | With | Examples | Mandatory? |
---|---|---|---|
SID | Account SID (Security Identifier). Generated by Kaleyra.io while creating an API key. | HXXXXXXX071US | True |
API_KEY | Your API Key generated by Kaleyra.io. | Ac4XXXXX21f | True |
CONTENT_TYPE | Indicates the format of the content the API will be processing. | application/json | True |
FROM_NUMBER | The number registered with WhatsApp business from which the message is to be sent. Ensure that the country code is prefixed to the number. (E164 format). | +1202XXXXXXX | True |
TO_NUMBER | A valid WhatsApp number of the recipient. Ensure that the country code is prefixed to the number. (E164 format). Note: You can add multiple recipients, separate each number using the comma (,) delimiter. | +1202XXXXXXX | True |
MESSAGE_TYPE | The type of message to be sent. | template | True |
CHANNEL_NAME | The channel on which message must be sent. | True | |
TEMPLATE_NAME | Name of the WhatsApp template that was created in the Kaleyra.io portal. This name must be approved by WhatsApp before you start using this API. | booking_confirm | True |
TEMPLATE_PARAMETERS | The values that you will pass when you want to send a message using the template. Since the values are dynamic, it must be passed through the key. Multiple parameters are allowed that must be separated with a comma. For a template that says: Hi your booking id is for date the params to be passed would be , <id_number>, . | "", "", "" | True |
LANGUAGE_CODE | The language code of the language that the template will allow. 'en' is the code for English. For a comprehensive list of supported languages, read this | en | True |
CALLBACK_URL | The URL that Kaleyra.io should send information to when your number receives a response. This URL can be accessed publicly. Click here for an example. | False |
- Response
If your request is successful, the response will be similar to the response shown below:
{
"id": "1b408138-61bf-46d3-9a1d-f13089dbf0a5",
"type": "template",
"createdDateTime": "2020-01-29 05:30:39+00:00",
"totalCount": 1,
"data": [
{
"message_id": "1b408138-61bf-46d3-9a1d-f13089dbf0a5:0",
"recipient": "1202XXXXXXX"
}
],
"error": {}
}
Error Codes
The below table provides information about the error codes you would receive when executing the WhatsApp Template Message API.
Error Code | Parameter | Description |
---|---|---|
E13008 | from_invalid | Invalid or in-correct input of the From number. |
E13009 | to_invalid | Invalid or in-correct input of the TO number. |
E13004 | template_params | The Template params are not matching. |
E13005 | template_name_missmatch | Invalid template. |
Updated 29 days ago