# Coupon Code Templates

{% hint style="info" %}
Coupon Code Templates are only available while using Cloud API.&#x20;
{% endhint %}

Coupon code templates are **marketing templates** that display a single copy code button. When tapped, the code is copied to the customer's clipboard.

<figure><img src="https://2248475362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuyAl2S0lSHJaNDXJHo7A%2Fuploads%2FgGbnbaG4XkaEyXuNHJDk%2FScreenshot%202023-08-30%20at%2018.32.51.png?alt=media&#x26;token=4414fcc0-ff83-42c5-b504-214fe7269d2f" alt=""><figcaption></figcaption></figure>

## Limitations <a href="#limitations" id="limitations"></a>

* Coupon code templates are currently not supported by the WhatsApp web client.
* Codes are limited to 15 characters.
* Button text cannot be customized.
* Templates are limited to one copy code button.

## Template Creation <a href="#creating-coupon-code-templates" id="creating-coupon-code-templates"></a>

Use the create template [endpoint](https://app.gitbook.com/s/-M4sMxKjL6eJRvZn6jeG-887967055/messaging-api/api-reference/templates#post-v1-configs-templates)  to create coupon code templates

#### Headers

| Name         | Type   | Description |
| ------------ | ------ | ----------- |
| D360-API-KEY | string |             |

{% tabs %}
{% tab title="200 " %}

```
object	{WABA Template}	
    name	string	optional
    namespace	string	optional
    category	string	optional
    components	array[object]	optional
        type	string	Allowed Values: BODY, HEADER, FOOTER, BUTTONS
        format	string	Allowed Values: TEXT, IMAGE, DOCUMENT, VIDEO
        text	string	optional
        example	string	optional
        buttons	object	optional
            type	string	Allowed Values: PHONE_NUMBER, URL, QUICK_REPLY
            text	string	required
            url	string	optional
            phone_number	string	optional
            example	string	optional
    language	string	optional
    rejected_reason	string	optional
    status	string	optional

```

{% endtab %}
{% endtabs %}

#### Post Body <a href="#post-body" id="post-body"></a>

```json
{
  "name": "<NAME>",
  "language": "<LANGUAGE>",
  "category": "MARKETING",
  "components": [
    ... // Additional components, if using
    {
      "type":"BUTTONS",
      "buttons": [
        {
          "type":"COPY_CODE",
          "example": "<EXAMPLE>"
        },
        ... // Additional buttons, if using
      ]
    }
  ]
}
```

#### Properties <a href="#properties" id="properties"></a>

| Placeholder                                          | Description                                                                                                                                                                                                 | Example Value        |
| ---------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- |
| <p><code>\<NAME></code></p><p><em>String</em></p>    | <p><strong>Required.</strong></p><p></p><p>Template name.<br></p><p>Maximum 512 characters.</p>                                                                                                             | `fall2023_promotion` |
| <p><code>\<LANGUAGE></code></p><p><em>Enum</em></p>  | <p><strong>Required.</strong></p><p></p><p>Template <a href="https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/supported-languages">language and locale code</a>.</p> | `en_US`              |
| <p><code>\<EXAMPLE></code></p><p><em>String</em></p> | <p><strong>Required.</strong><br></p><p>Coupon code to be copied when tapped.<br></p><p>Maximum 15 characters.</p>                                                                                          | `25OFF`              |

**Example Request**

```json
{
  "name": "coupon_code_fall2023_25off",
  "language": "en_US",
  "category": "MARKETING",
  "components": [
    {
      "type": "HEADER",
      "format": "TEXT",
      "text": "Our Fall Sale is on!"
    },
    {
      "type": "BODY",
      "text": "Shop now through November and use code {{1}} to get {{2}} off of all merchandise!",
      "example": {
        "body_text": [
          [
            "25OFF",
            "25%"
          ]
        ]
      }
    },
    {
      "type": "BUTTONS",
      "buttons": [
        {
          "type": "QUICK_REPLY",
          "text": "Unsubscribe"
        },
        {
          "type": "COPY_CODE",
          "example": "250FF"
        }
      ]
    }
  ]
}
```

#### Example Response <a href="#example-response" id="example-response"></a>

```json
{
  "category" : "MARKETING",
  "id" : "1924084211297547",
  "status" : "PENDING"
}
```

## Sending Coupon Templates <a href="#sending-coupon-templates" id="sending-coupon-templates"></a>

Use the Cloud API to send approved coupon code templates in template messages

<mark style="color:green;">`POST`</mark> `https://waba-v2.360dialog.io/messages`

#### Request Body

| Name               | Type    | Description                                                                                                                                                                                                                                                                                                           |
| ------------------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| to                 | string  | Recipient wa\_id                                                                                                                                                                                                                                                                                                      |
| type               | string  | Message type                                                                                                                                                                                                                                                                                                          |
| language           | string  | Template language                                                                                                                                                                                                                                                                                                     |
| policy             | string  | Delivery policy                                                                                                                                                                                                                                                                                                       |
| code               | string  | Language code                                                                                                                                                                                                                                                                                                         |
| name               | string  | Template name                                                                                                                                                                                                                                                                                                         |
| messaging\_product | string  | <p><strong>Required only for Cloud API.</strong><br>Messaging service used for the request. Use <code>"whatsapp"</code>.</p>                                                                                                                                                                                          |
| index              | integer | <p><strong>Required.</strong></p><p>Indicates order in which button should appear, if the template uses multiple buttons.<br></p><p>Buttons are zero-indexed, so setting value to <code>0</code> will cause the button to appear first, and another button with an index of <code>1</code> will appear next, etc.</p> |
| cupon\_code        | string  | <p><strong>Required.</strong></p><p></p><p>The coupon code to be copied when the customer taps the button.</p>                                                                                                                                                                                                        |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
It is only possible to send Templates with an Active status. A message template's status can change automatically from **Active** to **Paused** or **Disabled** based on feedback from customers. For this reason, we recommend that you [monitor status changes](#monitoring-status-changes) to take appropriate actions whenever a message template that you rely upon becomes, or is in danger of becoming, paused or disabled.
{% endhint %}

#### Properties <a href="#properties" id="properties"></a>

| Placeholder                                               | Description                                                                                                                                                                                                                                                                                                                     | Example Value                |
| --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- |
| <p><code>\<TO></code></p><p><em>String</em></p>           | <p><strong>Required.</strong></p><p></p><p>The WhatsApp ID or phone number of the customer to send the message to.</p>                                                                                                                                                                                                          | `+16505551234`               |
| <p><code>\<NAME></code></p><p><em>String</em></p>         | <p><strong>Required.</strong></p><p></p><p>Name of the template to be sent.</p>                                                                                                                                                                                                                                                 | `coupon_code_fall2023_25off` |
| <p><code>\<CODE></code></p><p><em>String</em></p>         | <p><strong>Required.</strong><br></p><p>The template's language and locale code.</p>                                                                                                                                                                                                                                            | `en_US`                      |
| <p><code>\<INDEX></code></p><p><em>Integer</em></p>       | <p><strong>Required.</strong></p><p></p><p>Indicates order in which button should appear, if the template uses multiple buttons.</p><p></p><p>Buttons are zero-indexed, so setting value to <code>0</code> will cause the button to appear first, and another button with an index of <code>1</code> will appear next, etc.</p> | `0`                          |
| <p><code>\<COUPON\_CODE></code></p><p><em>String</em></p> | <p><strong>Required.</strong></p><p><br></p><p>The coupon code to be copied when the customer taps the button.</p>                                                                                                                                                                                                              | `25OFF`                      |

#### **Post Body Example**

```json
{
  "messaging_product": "whatsapp",
  "to": "<TO>",
  "type": "template",
  "template": {
    "name": "<NAME>",
    "language": {
      "code": "<CODE>"
    },
    "components": [
      ... // Additional components, if using
      {
        "type": "button",
        "sub_type": "COPY_CODE",
        "index": <INDEX>,
        "parameters": [
          {
            "type": "coupon_code",
            "coupon_code": "<COUPON_CODE>"
          }
        ]
      }
    ]
  }
}
```

#### **Example Request** <a href="#response-syntax" id="response-syntax"></a>

```json
{
  "messaging_product": "whatsapp",
  "to": "16505551234",
  "type": "template",
  "template": {
    "name": "coupon_code_fall2023_25off",
    "language": {
      "code": "en_US"
    },
    "components": [
      {
        "type": "body",
        "parameters": [
          {
            "type": "text",
            "text": "25OFF"
          },
          {
            "type": "text",
            "text": "25%"
          }
        ]
      },
      {
        "type": "button",
        "sub_type": "COPY_CODE",
        "index": 1,
        "parameters": [
          {
            "type": "coupon_code",
            "coupon_code": "25OFF"
          }
        ]
      }
    ]
  }
}
```
