# Create and send WhatsApp Template messages to end users

To send business communications to end users, you can use either templates or free-form messages.

You can send a **free-form message** only if end user initiates the communication. You can send these messages only within the [messaging window](https://www.infobip.com/docs/whatsapp/remaining-compliant#messaging-window).

To initiate communication or to send messages outside the messaging window, you must use **Templates**. A WhatsApp template is a preformatted message that is approved by Meta.

This tutorial shows how to create WhatsApp templates and send them to end users. The tutorial uses a [**Rich media**](https://www.infobip.com/docs/whatsapp/message-types-and-templates/message-templates#text-and-rich-media-template-message-templates) template and a [**Carousel**](https://www.infobip.com/docs/whatsapp/message-types-and-templates/message-templates#carousel-template-message-templates) template for **Marketing**. You can modify the steps in the tutorial to use other template types.

## Products and channels [#products-channels]

- [WhatsApp](https://www.infobip.com/docs/whatsapp)
- [Broadcast](https://www.infobip.com/docs/broadcast)

## Prerequisites [#prerequisites]

- **Infobip account** with **WhatsApp** enabled.

    [Broadcast](https://www.infobip.com/docs/broadcast) is enabled by default with your Infobip account.

    If you do not have an account, [create a free trial account](https://www.infobip.com/docs/essentials/getting-started/create-an-account) and select the **WhatsApp** channel on the welcome screen.
- WhatsApp phone number that is registered with Infobip. You cannot use Infobip's test phone number.
- Infobip API key with the ```whatsapp:message:send``` scope. For more information, refer to [API authorization](https://www.infobip.com/docs/essentials/api-essentials/api-authorization).

## Process overview [#process-overview]

This tutorial shows how to send WhatsApp Template messages over the following:

- Over the Infobip web interface through Broadcast.
- Over the WhatsApp API.

### Over the Infobip Web interface through Broadcast [#web-interface-process-overview]

1. [Create the WhatsApp template](https://www.infobip.com/docs/tutorials/send-whatsapp-template-messages#create-template-web-interface): Create either a [**Rich media**](https://www.infobip.com/docs/whatsapp/message-types-and-templates/message-templates#text-and-rich-media-template-message-templates) template or a [**Carousel**](https://www.infobip.com/docs/whatsapp/message-types-and-templates/message-templates#carousel-template-message-templates) template.

    Note
You cannot use a shared sender to create a WhatsApp template. But the WhatsApp shared sender has a list of predefined templates that you can use for testing purposes.

2. Register the template with Meta.
3. [Send the template message](https://www.infobip.com/docs/tutorials/send-whatsapp-template-messages#send-broadcast-web-interface) to end users over Broadcast.

### Over the WhatsApp API [#api-process-overview]

1. [Create](https://www.infobip.com/docs/tutorials/send-whatsapp-template-messages#create-template-api) a WhatsApp **Carousel** template.

    Note
You cannot use a shared sender to create a WhatsApp template. But the WhatsApp shared sender has a list of predefined templates that you can use for testing purposes.

2. [Register the template](https://www.infobip.com/docs/tutorials/send-whatsapp-template-messages#register-template-api) with Meta.
3. [Send the template message](https://www.infobip.com/docs/tutorials/send-whatsapp-template-messages#send-message-api) to end users over the WhatsApp API.

## Implementation over the Infobip web interface [#implementation-web-interface]

This section shows how to create and send **Rich media** and **Carousel** templates over Broadcast.

### Create a WhatsApp template [#create-template-web-interface]

1. On the [**Infobip web interface**](https://portal.infobip.com/login), go to **Channels and numbers** > **Channels** > **WhatsApp** > **Senders** tab. A list of all WhatsApp senders for your account and their statuses is displayed.
2. Select **Register template** next to the sender on which you want to register the template.
3. Select the template type that is suitable for your use case. This tutorial shows how to create a **Marketing** template.
    - Marketing
    - Utility
    - Authentication: These templates are predefined by Meta. You cannot customize the body of the templates.

    For more information about each type of template, refer to the [Meta documentation](https://developers.facebook.com/docs/whatsapp/updates-to-pricing/new-template-guidelines).
4. Configure the template.

    - **Rich media**: Refer to [Configure the Rich media template](https://www.infobip.com/docs/tutorials/send-whatsapp-template-messages#configure-the-rich-media-template).
    - **Carousel**: Refer to [Configure the Carousel template](https://www.infobip.com/docs/tutorials/send-whatsapp-template-messages#configure-the-carousel-template).
5. A preview of your template is shown on the left side, displaying how end users will see it. Make sure that it meets your requirements.
6. Select **Register template**.

The template is sent to Meta for approval. The approval process usually takes only a few minutes but can take a maximum of 24 hours.

After the template is approved, it is ready for sending live traffic.

To check the status of the template, do the following:

1. Go to **Channels and numbers** > **Channels** > **WhatsApp** > **Senders** tab.
2. Select the three dots next to the sender and select **Manage templates**. A list of all the templates that you submitted is displayed.
3. To find the template you created, enter the template name in the Search field. You can see the status of the template.

### Configure the Rich media template [#configure-rich-media-template-web-interface]

1. Select the type of content that you want to send to end users. To create a rich media template, select **Text and rich media**.
2. Complete the following fields in the template:
   - **WhatsApp template name**: Can contain only lowercase letters and underscore. The name must be unique for each language.
   - **Language**
   - **Content**: Add the message that you want to send to end users.
   - (Optional) **Parameters**: Add placeholders along with their values. Mark them in increasing order. Example: {{1}}, {{2}}, {{3}}.

        How placeholders work
When you add placeholders like {{1}}, {{2}}, etc, these will be filled with actual values when you send the message. For example, if your template says "Hi {{1}}", and you provide "John" as the value, the user will receive "Hi John".

3. Add headers, footers, and buttons to create a media template. For information about the supported media formats, refer to the [WhatsApp documentation](https://www.infobip.com/docs/whatsapp/message-types-and-templates#supported-message-formats).
   - To add a header, select **Add header**. Choose one of the following types of headers and provide an example:
     - Text
     - Image
     - Video
     - Document
     - Location
   - To add a footer, select **Add footer**. Add the text that you want in the footer.
   - To add buttons, select **Add button**. A list of the available types of buttons is displayed:
     - Quick reply
     - Call
     - Click to URL

      Choose the relevant type depending on your use case. This tutorial uses the **Quick reply** button.

      Configure the fields in the button.

### Configure the Carousel template [#configure-carousel-template-web-interface]

1. Select the type of content that you want to send to end users. To create a carousel template, select **Carousel**.
2. Complete the following fields in the template:
   - **WhatsApp template name**: Can contain only lowercase letters and underscore. The name must be unique for each language.
   - **Language**
   - **Content**: Add the message that you want to send to end users.
   - (Optional) **Parameters**: Add placeholders along with their values. Mark them in increasing order. Example: {{1}}, {{2}}, {{3}}.

3. Add headers and buttons to create a media template. For information about the supported media formats, refer to the [WhatsApp documentation](https://www.infobip.com/docs/whatsapp/message-types-and-templates#supported-message-formats).

    - To add a header, choose one of the following types of headers:

      - Image
      - Video

      The header type is applied to all the cards that you create.

    - To add buttons, select **Add button**. A list of the available types of buttons is displayed:

        - Quick reply
        - Call
        - Click to URL

      Choose the relevant type depending on your use case. You can add a maximum of 2 buttons to each card.

      The button type is applied to all the cards that you create.

4. For each card in the carousel, do the following:
   1. Select **Browse** to add header (media) sample.
   2. Add the body message and button text for the button.
   3. If you selected **click-to-URL** button, add the website URL.

    You can use either dynamic or static URLs, depending on your use case.

    To create a dynamic URL button, add a parameter into your URL for the dynamic part. Example: *{{1}}*. Add a sample value for the placeholder.

   You can add a maximum of 10 cards.

### Send the WhatsApp template message over Broadcast [#send-broadcast-web-interface]

1. On the [**Infobip web interface**](https://portal.infobip.com/login), go to **Moments** > **Broadcasts**.
2. Select **Create broadcast**.
3. Select **WhatsApp** as the channel.
4. Configure the **Recipients** and **Sender** fields.
5. Select **Create content** to begin designing your message.

6. On the right-hand side, all the templates that use the selected sender are listed. Use Filter and Search to find the template that you created.
7. Select **Use** next to the template.
8. If your template type is **Carousel**, follow these steps:

   1. Enter the image URL.
   2. Specify the details for the button as applicable. Example: For a dynamic URL button, enter the dynamic part of the URL.
   3. Enter the details for all the cards in the carousel.
9. If your template type is **Rich media**, follow these steps:

   1. Enter the values for placeholders.
   2. If the template contains media in the header, enter the URL that contains the media.
   3. (Optional) Add button payload to send additional data when the end user selects a button. This data is displayed in message reports.
10. Configure the other fields in the template.
11. Select **Done designing**.
12. (Optional) Enable failover to SMS so that if the WhatsApp message is not delivered to the end user, the broadcast will try to send the message over SMS.

    1. Select **Failover to SMS**.
    2. Define the SMS sender and SMS content.
13. Configure the other fields in the broadcast as required.
14. Check all the fields and rename the broadcast if required.
15. Select **Continue to preview**.
16. Check the preview and make sure that all the information is correct.
17. Select **Launch** to send the broadcast.

To track the status of the broadcast, go to **Moments** > **Broadcasts**.

## Implementation over the WhatsApp API [#implementation-api]

This section shows how to create and send a **Carousel** template over the WhatsApp API.

Note
This section focuses on carousel templates. For Rich media templates via API, the structure is similar. Refer to the [API documentation](https://www.infobip.com/docs/api/channels/whatsapp/whatsapp-service-management/create-whatsapp-template) for additional template types.

### Create a WhatsApp template [#create-template-api]

Use the [Create a WhatsApp template](https://www.infobip.com/docs/api/channels/whatsapp/whatsapp-service-management/create-whatsapp-template) endpoint to create your template.

#### Example request

```curl
curl -L -g 'https://{baseUrl}/whatsapp/2/senders/447796344125/templates' \
-H 'Authorization: {authorization}' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
  "name": "template_with_carousel",
  "language": "en",
  "category": "MARKETING",
  "structure": {
    "body": {
      "text": "Hi {{1}}, \nPlease check our offer below",
      "examples": ["John"]
    },
    "carousel": {
      "cards": [
        {
          "header": {
            "example": "https://example.com/image1.png",
            "format": "IMAGE"
          },
          "body": {
            "text": "Would you like to buy this phone?"
          },
          "buttons": [
            {
              "text": "Buy",
              "type": "QUICK_REPLY"
            }
          ]
        },
        {
          "header": {
            "example": "https://example.com/image2.png",
            "format": "IMAGE"
          },
          "body": {
            "text": "And would you like to buy this phone?"
          },
          "buttons": [
            {
              "text": "Buy",
              "type": "QUICK_REPLY"
            }
          ]
        }
      ]
    }
  }
}'
```

#### Key points

- After you create a template, Infobip sends it to Meta for validation. To edit the template, follow the <apidocslink href="channels/whatsapp/whatsapp-service-management/edit-whatsapp-template">editing rules</apidocslink>.

- In the ```category``` parameter, specify one of the following template categories:
  - ```MARKETING```
  - ```UTILITY```
  - ```AUTHENTICATE```

  This tutorial uses ```MARKETING```. The fields in the reference adapt based on your selection. Refer to the API documentation to configure these fields.

- In the ```buttons``` parameter, specify the button type. This tutorial uses ```QUICK_REPLY```. The fields in the reference adapt based on your selection. Refer to the API documentation to configure these fields.

- For carousel templates, header examples must be direct URLs without placeholders. Body text in carousel cards should not include placeholders unless you provide matching examples.

- Make sure that your images are downloadable and <apidocslink href="channels/whatsapp/whatsapp-service-management/create-whatsapp-template">supported by the API</apidocslink>.

### Register the WhatsApp template [#register-template-api]

Infobip manages your template registration. During the process, you can edit your template following the <apidocslink href="channels/whatsapp/whatsapp-service-management/edit-whatsapp-template">editing rules</apidocslink>. You can also set up a <apidocslink href="channels/whatsapp/whatsapp-service-management/receive-whatsapp-message-template-update-events">webhook</apidocslink> to get updates about your template registration process.

### Send the WhatsApp template message to end users [#send-message-api]

After the template is registered, use the <apidocslink href="channels/whatsapp/whatsapp-outbound-messages/send-whatsapp-template-message">Send WhatsApp Template message</apidocslink> API to send the message to end users.

#### Example request

```curl
curl -L -g 'https://{baseUrl}/whatsapp/1/message/template' \
-H 'Authorization: {authorization}' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
  "messages": [
    {
      "from": "447796344125",
      "to": "441134960001",
      "messageId": "a28dd97c-1ffb-4fcf-99f1-0b557ed381da",
      "content": {
        "templateName": "template_with_carousel",
        "templateData": {
          "body": {
            "placeholders": ["John"]
          },
          "carousel": {
            "cards": [
              {
                "header": {
                  "type": "IMAGE",
                  "mediaUrl": "https://example.com/phone1.jpg"
                }
              },
              {
                "header": {
                  "type": "IMAGE",
                  "mediaUrl": "https://example.com/phone2.jpg"
                }
              }
            ]
          }
        },
        "language": "en"
      }
    }
  ]
}'
```

#### How placeholders work

When you create a template, the message text is stored at Meta with placeholders (```{{1}}```, ```{{2}}```, etc.). When sending the message, you only provide the **values** to fill those placeholders, not the full text.

Example:

Template body text (stored at Meta):
```
Hi {{1}},
Please check our offer below
```

Send request provides values:
```json
"body": {
  "placeholders": ["John"]
}
```

User receives:
```
Hi John,
Please check our offer below
```

For carousel templates:
- The main body text and card body texts are stored in the template
- You only provide placeholder values for the main body and media URLs for each card header
- Card body texts cannot have placeholders and are always static

#### Key points

- Use the international number formatting when adding a number to the ```to``` field. For example, for British numbers, the value will look like this: ```441234567890```.

- The ```from``` field must match the sender used to create the template.

- Provide placeholder values in the same order as they appear in the template. The first value fills ```{{1}}```, the second fills ```{{2}}```, etc.

- For carousel templates, provide media URLs for each card's header in the ```carousel.cards``` array. The number of cards must match the template definition.

- Card body texts are static and stored in the template. You cannot change them when sending.

- The ```language``` parameter must match the language code used when creating the template (e.g., ```"en"```).

- The media that you add must follow the specifications. Example: size and format.

- For ```QUICK_REPLY``` buttons it is mandatory to include a parameter.

You can also refer to <apidocslink href="channels/whatsapp">other Infobip APIs</apidocslink> for WhatsApp.

### Track message delivery [#track-delivery-api]

After you send the request, you should receive a WhatsApp message on the device that you have specified in the ```to``` field and see a ``200 OK`` response.

```json
{  "to": "441134960001",  "messageCount": 1,  "messageId": "a28dd97c-1ffb-4fcf-99f1-0b557ed381da",  "status": {    "groupId": 1,    "groupName": "PENDING",    "id": 7,    "name": "PENDING_ENROUTE",    "description": "Message sent to next instance"  }}
```

The response informs you that the message is successfully queued in the Infobip platform and will be sent to Meta  for approval.

To see whether the message was delivered to the recipient, use the <apidocslink href="channels/whatsapp/receive-whatsapp-delivery-reports">Delivery report</apidocslink> feature.