Create a WhatsApp Template with Sample Media

POST Method

Kaleyra.io allows you to create WhatsApp templates with sample media using the API. After you create a WhatsApp template with sample media, it has to get approved by Meta before you can use the WhatsApp template with sample media to send messages.

Template Category

📘

Note:

Marketing, Authentication, and Utility template categories are supported by Kaleyra. For more information, see the WhatsApp Template Category page.

Base URL

<https://api.kaleyra.io/v1/><SID>

To create the WhatsApp templates with sample media, perform the following:

Signup or Login to Kaleyra.io and Create your API key

Refer to the Create an API Key page for steps to create your API key. To view the API Key and the SID, see View API Key and SID.

📘

Note:

After you sign up, your account will be on the trial version. You must complete the KYC to access all the features in Kaleyra.io.

API Request to Create WhatsApp Templates

To create the WhatsApp templates, use the whatsapp/templates endpoint with the following request method:

Request format

The following is the request format to create WhatsApp template with sample media:

curl --location 'https://api.kaleyra.io/v1/<sid>/whatsapp/template' \
--header 'api-key: <api_key>' \
--form 'name="<name>"' \
--form 'category="<category>"' \
--form 'language="<language>"' \
--form 'header="{\"type\":\"image\"}";type=application/json' \
--form 'body="<body>"' \
--form 'sample_body="<sample body>"' \
--form 'footer="<footer>"' \
--form 'waba_id="<waba_id>"' \
--form 'button_data="[
	{
    \"type\":\"<type>\",
    \"quick_reply1\":\"<quick_reply1>\",
    \"quick_reply2\":\"<quick_reply2>\",
	\"quick_reply3\":\"<quick_reply3>\"
}
]";type=<type>' \
--form 'sample_media_url="<sample_media_url>"' \
--form 'sample_media_file="<sample_media_file>"'

Sample Request Format

The following is the sample request format to create WhatsApp templates with sample media:

curl --location 'https://api.kaleyra.io/v1/HXXXXXXX071US/whatsapp/template' \
--header 'api-key: Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3' \
--form 'name="template_01"' \
--form 'category="marketing"' \
--form 'language="en"' \
--form 'header="{\"type\":\"image\"}";type=application/json' \
--form 'body="Hi, this is a sample message"' \
--form 'sample_body="Up to 70% off on Home, Kitchen, and outdoor"' \
--form 'footer="This is the footer content"' \
--form 'waba_id="13XXXXXXXXXXXXX"' \
--form 'button_data="[
	{
    \"type\":\"QUICK_REPLY\",
    \"quick_reply1\":\"Bye\",
    \"quick_reply2\":\"Sample\",
	\"quick_reply3\":\"Okie\"
}
]";type=application/json' \
--form 'sample_media_url="https://www.kaleyra.com/wp-content/uploads/kaleyra.png"' \
--form 'sample_media_file=@"/C:/Users/company_A/Downloads/videoplayback.mp4"'

Parameter and Data Types

The following is the list of parameter and data types supported to create a WhatsApp template with a sample media:

ParameterData TypeDescriptionExampleMandatory
sidStringAccount SID (Security Identifier).HXXXXXXX071USTrue
api-keyStringAPI key generated from Kaleyra.io account.Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3True
nameStringTemplate name.template_01True
categoryStringSelect one of the following:

- Marketing
- Authentication
- Utility
marketingTrue
languageStringThe language in which, you want to create the template.enTrue
headerJSON/StringSelect one of the following:

- Image
- Video
- Document
- Text.
{"type": "image"}True
bodyStringBody of the message.Hi, this is a sample message.True
sample_bodyStringSample value for the variable pass in the body field.Up to 70% off on Home, Kitchen, and outdoorTrue
footerStringFooter textThis is the footer contentFalse
waba_idStringWhatsApp Business Account ID13XXXXXXXXXXXXXTrue
button_dataArray of ObjectsSpecifies the type of button in the template.[
{
"type":"QUICK_REPLY",
"quick_reply1":"Bye",
"quick_reply2":"Sample",
"quick_reply3":"Okie"
}
]
False
sample_media_fileMediaUpload a media file from the following list:

- Image (.JPG, .PNG, or .JPEG)
- Video (.mp4)
- Documents (.pdf)
@/C:/Users/company_A/Downloads/videoplayback.mp4Conditional (True/False) Note: If the header_type is Image/Video/PDF, then the sample_media_file is mandatory.
sample_media_url StringThe sample media URL should be public and have a file extension and valid SSL certificate.
Note: URL path is supported for image/video/media instead of uploading it.
If both media_file and media_url are passed in the API request, then only "media_file" will be considered.
https://www.kaleyra.com/wp-content/uploads/kaleyra.pngConditional (True/False) Note: If the header_type is Image/Video/PDF, then the sample_media_url is mandatory instead of sample_media_file.

The following table lists the button_data attributes:

ParameterData TypeDescriptionExampleMandatory?
type (button_data) (Optional)StringIt can be one of the following:

- QUICK_REPLY
- PHONE_NUMBER
- URL
QUICK_REPLYFalse
quick_reply_1StringSpecifies the quick reply button text.ByeFalse
quick_reply_2StringSpecifies the quick reply button text.SampleFalse
quick_reply_3StringSpecifies the quick reply button text.OkieFalse

Sample Success Response

The following success message appears with status 200:

{
    "status": 200,
    "message": "Template created successfully.",
    "data": [],
    "error": {}
}

Sample Failure Response Format

  1. Sample validation error when API is unable to create the WhatsApp templates with sample media:
{
    "error": {
        "code": "E996",
        "type": "VALIDATION_ERROR",
        "parameter": "message",
        "message": "Unable to create the Template.",
        "reference": ""
    }
}
  1. Sample validation error when body and sample_body don't have the same content in the WhatsApp templates with sample media:
{
    "error": {
        "code": "E996",
        "type": "VALIDATION_ERROR",
        "parameter": "message",
        "message": "The body and sample_body don't have the same content. Please verify and try again.",
        "reference": ""
    }
}
  1. Sample validation error when template name already exists in the WhatsApp templates with sample media:
{
    "error": {
        "code": "E996",
        "type": "VALIDATION_ERROR",
        "parameter": "name",
        "message": "Template name already taken!",
        "reference": ""
    }
}