How to Send a Media Template Message

Media templates must be pre-approved by Facebook. You can submit your template for approval using WhatsApp Template Manager.

In order to send a WhatsApp media template message, you must use one of the Conversations API endpoints for sending messages (see bellow). The message type must be hsm and the content.hsm must be set.

Image template message

Considering the following media template is approved by Facebook.

Media template with buttons

In order to send a WhatsApp message using this template, you must perform the following HTTP request to Conversations API. The following example uses the endpoint POST /v1/send, however, you can also use the other endpoints for sending messages, please check the Conversations API reference for details about the request.

curl -X "POST" "https://conversations.messagebird.com/v1/send" \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"content": {
"hsm": {
"language": {
"code": "en"
},
"components": [
{
"type": "header",
"parameters": [
{
"type": "image",
"image": {
"url": "https://www.messagebird.com/images/banner.jpg"
}
}
]
},
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "John"
},
{
"type": "text",
"text": "MB93824"
},
{
"type": "text",
"text": "2 days"
},
{
"type": "text",
"text": "MessageBird"
}
]
}
],
"namespace": "20132cc4_f094_b090_d255_35677159bbdt",
"templateName": "33172012024_ship_img_but_1"
}
},
"to": "+31612345678",
"type": "hsm",
"from": "2181d3bb46f5449aad0309f852b36ba5"
}'
  • content.hsm.namespace can be found in the WhatsApp Templates Manager of your Facebook Business account, or, in case you don't have access to it, please contact our support team
  • content.hsm.language.code is the language which the template message should be sent
  • content.hsm.templateName is the template name
  • content.hsm.components[0].type must be header as the template has an image header
  • content.hsm.components[0].image.url must contain an image URL because the template has an image header
  • content.hsm.components[1].type must be body because the template has variables in the message body
  • content.hsm.components[1].type.parameters must contain a list of objects with the values that should be set in the variables
  • content.hsm.components[1].type.parameters[0..3].type must be text as the variable type is text
  • content.hsm.components[1].type.parameters[0..3].text contains the value of the variable
  • to is the phone number of the recipient
  • type must be hsm because this is a template message
  • from must be your WhatsApp channel ID

The HTTP response should be 202 Accepted and it should contain the message ID.

{
"id": "4a968dd619f54d9582440d15aaa791ec"
}

Video template message

Considering the following media template is approved by Facebook.

Video template

In order to send a WhatsApp message using this template, you must perform the following HTTP request to Conversations API. The following example uses the endpoint POST /v1/send, however, you can also use the other endpoints for sending messages, please check the Conversations API reference for details about the request.

curl -X "POST" "https://conversations.messagebird.com/v1/send" \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"to": "31612345678",
"channelId": "2181d3bb46f5449aad0309f852b36ba5",
"type": "hsm",
"content": {
"hsm": {
"namespace": "20132cc4_f094_b090_d255_35677159bbdt",
"templateName": "test_media_template_with_video_header",
"language": {
"policy": "deterministic",
"code": "en"
},
"components": [
{
"type": "header",
"parameters": [
{
"video": {
"url": "https://www.yourcompany.com/videos/sample.mp4"
},
"type": "video"
}
]
},
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "Robert"
}
]
}
]
}
}
}'
  • content.hsm.namespace can be found in the WhatsApp Templates Manager of your Facebook Business account, or, in case you don't have access to it, please contact our support team
  • content.hsm.language.code is the language which the template message should be sent
  • content.hsm.templateName is the template name
  • content.hsm.components[0].type must be header as the template has a video header
  • content.hsm.components[0].video.url must contain a video URL because the template has a video header
  • content.hsm.components[1].type must be body because the template has variables in the message body
  • content.hsm.components[1].type.parameters must contain a list of objects with the values that should be set in the variables
  • content.hsm.components[1].type.parameters[0].type must be text as the variable type is text
  • content.hsm.components[1].type.parameters[0].text contains the value of the variable
  • to is the phone number of the recipient
  • type must be hsm because this is a template message
  • from must be your WhatsApp channel ID

The HTTP response should be 202 Accepted and it should contain the message ID.

{
"id": "4a968dd619f54d9582440d15aaa791ec"
}

Document template message

Considering the following media template is approved by Facebook.

Document template

In order to send a WhatsApp message using this template, you must perform the following HTTP request to Conversations API. The following example uses the endpoint POST /v1/send, however, you can also use the other endpoints for sending messages, please check the Conversations API reference for details about the request.

curl -X "POST" "https://conversations.messagebird.com/v1/send" \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"to": "31612345678",
"channelId": "2181d3bb46f5449aad0309f852b36ba5",
"type": "hsm",
"content": {
"hsm": {
"namespace": "20132cc4_f094_b090_d255_35677159bbdt",
"templateName": "test_media_template_with_document_header",
"language": {
"policy": "deterministic",
"code": "en"
},
"components": [
{
"type": "header",
"parameters": [
{
"document": {
"url": "https://www.yourcompany.com/documents/contract.pdf"
},
"type": "document"
}
]
},
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "Robert"
}
]
}
]
}
}
}'
  • content.hsm.namespace can be found in the WhatsApp Templates Manager of your Facebook Business account, or, in case you don't have access to it, please contact our support team
  • content.hsm.language.code is the language which the template message should be sent
  • content.hsm.templateName is the template name
  • content.hsm.components[0].type must be header as the template has a document header
  • content.hsm.components[0].document.url must contain a document URL because the template has a document header
  • content.hsm.components[1].type must be body because the template has variables in the message body
  • content.hsm.components[1].type.parameters must contain a list of objects with the values that should be set in the variables
  • content.hsm.components[1].type.parameters[0].type must be text as the variable type is text
  • content.hsm.components[1].type.parameters[0].text contains the value of the variable
  • to is the phone number of the recipient
  • type must be hsm because this is a template message
  • from must be your WhatsApp channel ID

The HTTP response should be 202 Accepted and it should contain the message ID.

{
"id": "4a968dd619f54d9582440d15aaa791ec"
}

Questions?

We’re always happy to help with code or other doubts you might have! Check out our Quickstarts, API Reference, Tutorials, SDKs, or contact our Support team.

Cookie Settings