# Sending Message Templates

```http
POST https://gateway.lipachat.com/api/v1/whatsapp/template
```

**Headers**

| Name         | Value                                                                          |
| ------------ | ------------------------------------------------------------------------------ |
| Content-Type | `application/json`                                                             |
| apiKey       | Get apiKey from App portal settings tab<https://app.lipachat.com/app/settings> |

**Body**

| Name                                        | Type   | Description                                                                                                        |
| ------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------ |
| messageId                                   | string | A unique identifier for the message. This will be used to track the message status and for deduplication purposes. |
| to                                          | string | PhonReceiver phone number. It should start with a country code.                                                    |
| from                                        | string | Sandbox number +254110090747 or your own WABA phone number.                                                        |
| template.name                               | string | Name of template                                                                                                   |
| template.language                           | string | Language code e.g en                                                                                               |
| template.category                           | string | Accepted values are: MARKETING, UTILITY or AUTHENTICATION                                                          |
| template.components.header.format           | string | Accepted values are: TEXT, IMAGE, VIDEO, DOCUMENT                                                                  |
| template.components.header.text             | string | Text to be sent on header                                                                                          |
| template.components.header.filename         | string | This is optional, applies to type document.                                                                        |
| template.components.header.example          | string | Should be present if text above has a variable.                                                                    |
| template.components.body.text               | string | Body text, accepts variables e.g Hello {{1}}, your balance is {{2}}                                                |
| template.components.body.examples           | array  | Should match number of variables passed in text. For the example above it should be \['John', '2000']              |
| template.components.footer.text             | string | Optional footer text.                                                                                              |
| template.components.buttons\[0].type        | string | Accepted values are: PHONE\_NUMBER, URL or QUICK\_REPLY.                                                           |
| template.components.buttons\[0].text        | string | Text on button above.                                                                                              |
| template.components.buttons\[0].phoneNumber | string | Should be passed if button type passed is PHONE\_NUMBER.                                                           |
| template.components.buttons\[0].url         | string | Should be passed if button type passed is URL.                                                                     |
| template.components.buttons\[0].example     | string | Applies for PHONE\_NUMBER and URL.                                                                                 |

**Example Requests:**

<details>

<summary>Request to send a template with type TEXT header.</summary>

```json
{
    "messageId": "d13ce19b-678f-4a94-a910-441cfbb25b9b",
    "to": "PHONE_NUMBER",
    "from": "BUSINESS_PHONE_NUMBER",
    "template": {
        "name": "offer_830",
        "languageCode": "en",
        "components": {
            "header": {
                "type": "TEXT",
                "parameter": "Discounts"
            },
            "body": {
                "placeholders": [
                    "John","123123"
                ]
            }
        }
    }
}
```

</details>

<details>

<summary>Request to send a template with type TEXT, no header.</summary>

```json
{
    "messageId": "5c9bd5ef-ebae-4071-9c26-3ba1ef693264",
    "to": "PHONE_NUMBER",
    "from": "BUSINESS_PHONE_NUMBER",
    "template": {
        "name": "offer_830",
        "languageCode": "en",
        "components": {
            "body": {
                "placeholders": [
                    "Gideon","123123"
                ]
            }
        }
    }
}
```

</details>

<details>

<summary>Request to send a template with type MEDIA (IMAGE, VIDEO, AUDIO) header.</summary>

```json
{
    "messageId": "5c9bd5ef-ebae-4071-9c26-3ba1ef693264",
    "to": "PHONE_NUMBER",
    "from": "BUSINESS_PHONE_NUMBER",
    "template": {
        "name": "declined_transfer",
        "languageCode": "en",
        "components": {
            "header":{
                "type": "IMAGE",
                "mediaUrl": "https://picsum.photos/id/237/200/300"
            },
            "body": {
                "placeholders": [
                    "John",
                    "Airtime",
                    "KES 100",
                    "Insufficient funds",
                    "funding your account"
                ]
            }
        }
    }
}
```

</details>

<details>

<summary>Request to send a template with type MEDIA (DOCUMENT) header.</summary>

```json
{
    "messageId": "5c9bd5ef-ebae-4071-9c26-3ba1ef693264",
    "to": "PHONE_NUMBER",
    "from": "BUSINESS_PHONE_NUMBER",
    "template": {
        "name": "transaction_alert",
        "languageCode": "en",
        "components": {
            "header":{
                "type": "DOCUMENT",
                "mediaUrl": "https://morth.nic.in/sites/default/files/dd12-13_0.pdf",
                "filename": "Transaction receipt"
            },
            "body": {
                "placeholders": [
                    "John",
                    "Airtime",
                    "KES 100"
                ]
            }
        }
    }
}
```

</details>

<details>

<summary>Request to send an Authentication template</summary>

```json
{
    "messageId": "{{$randomUUID}}",
    "to": "{{YOUR_PHONE_NUMBER}}",
    "from": "{{BUSINESS_PHONE_NUMBER}}",
    "template": {
        "name": "lipachat_auth_template",
        "languageCode": "en",
        "components": {
            "body": {
                "placeholders": [
                    "123456"
                ]
            },
            "buttons": [
                {
                    "type": "URL",
                    "index": 0,
                    "parameter": "123456"
                }
            ]
        }
    }
}
```

</details>

<details>

<summary>Request to send a template with no params</summary>

```json
{
    "messageId": "{{$randomUUID}}",
    "to": "{{YOUR_PHONE_NUMBER}}",
    "from": "{{BUSINESS_PHONE_NUMBER}}",
    "template": {
        "name": "template_with_no_params",
        "languageCode": "en",
        "components": {
        }
    }
}
```

</details>

**Response**

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

```json
{
  "timestamp": "2023-11-22T09:59:26.720575619",
  "data": {
    "messageId": "4530f474-9d84-4905-a26f-6ba473ab890d",
    "waId": "wamid.HBgMMjU0NzE3NzQ2NTY1FQIAERgSMjNCREE1Q0YwQUJFQzE0NUQ2AA==",
    "status": "SENT",
    "statusDesc": "Template sent successfully"
  },
  "status": "success",
  "message": "",
  "errors": null
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "timestamp": "2024-09-15T20:06:38.675567555",
    "data": null,
    "status": "error",
    "message": "Request failed. please provide missing content",
    "errors": null
}
```

{% endtab %}

{% tab title="401" %}

```json
{
    "timestamp": "2024-09-15T20:07:23.464199513",
    "data": null,
    "status": "success",
    "message": "Invalid credentials",
    "errors": null
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lipachat.com/api/templates/send-template.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
