# Creating a Template

<mark style="color:green;">`POST`</mark> [`https://gateway.lipachat.com/api/v1/template/PHONE_NUMBER`](https://gateway.lipachat.com/api/v1/template/PHONE_NUMBER)

{% hint style="info" %}
Pass your WABA number or Sandbox phone number as the value of *PHONE\_NUMBER*
{% endhint %}

**Headers**

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

**Body**

<table><thead><tr><th width="338">Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>name</td><td>string</td><td>Name of template. Can only contain <strong>lowercase alphanumeric</strong> characters and underscores ( _ ). No other characters or white space are allowed.</td></tr><tr><td>language</td><td>string</td><td>Language code e.g en</td></tr><tr><td>category</td><td>string</td><td>Accepted values are: MARKETING, UTILITY or AUTHENTICATION.</td></tr><tr><td>component.header.format</td><td>string </td><td>Accepted values are: TEXT, IMAGE, VIDEO, DOCUMENT</td></tr><tr><td>component.header.text</td><td>string </td><td>Text to be sent on header</td></tr><tr><td>component.header.example</td><td>string </td><td>Should be present if text above has a variable.</td></tr><tr><td>component.body.text</td><td>string</td><td>Body text, accepts variables e.g Hello {{1}}, your balance is {{2}}</td></tr><tr><td>component.body.examples</td><td>array</td><td>Should match number of variables passed in text. For the example above it should be ['John', '2000']</td></tr><tr><td>component.footer.text</td><td>string</td><td>Optional footer text.</td></tr><tr><td>component.buttons[0].type</td><td>string</td><td>Accepted values are: PHONE_NUMBER, URL or QUICK_REPLY.</td></tr><tr><td>component.buttons[0].text</td><td>string</td><td>Text on button above.</td></tr><tr><td>component.buttons[0].phoneNumber</td><td>string</td><td>Should be passed if button type passed is PHONE_NUMBER.</td></tr><tr><td>component.buttons[0].url</td><td>string</td><td>Should be passed if button type passed is URL.</td></tr><tr><td>component.buttons[0].example</td><td>string</td><td>Applies for PHONE_NUMBER and URL.</td></tr></tbody></table>

> component.header, component.footer, component.buttons objects are optional.

Sample Requests:

<details>

<summary>Request to create a template with header and body.</summary>

```json
{
    "name": "temp_lower_68",
    "language": "en",
    "category": "MARKETING",
    "component": {
        "header": {
            "format": "TEXT",
            "text": "{{1}} registration",
            "example": "July"
        },
        "body": {
            "text": "Hi {{1}}, we have a new user registered click {{2}} to view.",
            "examples": [
                "John",
                "http://lipachat.com/offers/ASHSH"
            ]
        }
    }
}
```

</details>

<details>

<summary>Request to create a template with header, body and footer.</summary>

```json
{
    "name": "temp_lower_68",
    "language": "en",
    "category": "MARKETING",
    "component": {
        "header": {
            "format": "TEXT",
            "text": "{{1}} registration",
            "example": "July"
        },
        "body": {
            "text": "Hi {{1}}, we have a new user registered click {{2}} to view.",
            "examples": [
                "John",
                "http://lipachat.com/offers/ASHSH"
            ]
        },
        "footer": {
            "text": "Thank you"
        }
    }
}
```

</details>

<details>

<summary>Request to create a template with header, body and quick reply</summary>

```json
{
    "name": "transaction_update",
    "language": "en",
    "category": "UTILITY",
    "component": {
        "body": {
            "text": "Dear {{1}},\nYour {{2}} payment of {{3}} ",
            "examples": [
                "Mary",
                "Airtime",
                "KES 100"
            ]
        },
        "footer": {
            "text": "The Test Bank Team"
        },
        "buttons": [
            {
                "type": "QUICK_REPLY",
                "text": "Ask a Question"
            },
            {
                "type": "QUICK_REPLY",
                "text": "Chat with Support"
            }
        ]
    }
}
```

</details>

<details>

<summary>Request to create a template with quick reply buttons</summary>

```json
{
    "name": "lipachat_marketing_quick_reply",
    "language": "en",
    "category": "MARKETING",
    "component": {
        "body": {
            "text": "Hi {{1}}, we noticed that you tried to reach us but we were not available. Would you like to:",
            "examples": [
                "Mary"
            ]
        },
        "footer": null,
        "buttons": [
            {
                "type": "PHONE_NUMBER",
                "text": "CALL US",
                "phoneNumber": "+254110090747",
                "example": "254110090747"
            },
            {
                "type": "URL",
                "text": "Raise a ticket",
                "url": "https://lipachat.com/raiseTicket",
                "example": "https://lipachat.com/raiseTicket"
            }
        ]
    }
}
```

</details>

<details>

<summary>Request to create a template with a media header</summary>

```json

{
    "name": "payment_processed",
    "language": "en",
    "category": "UTILITY",
    "component": {
        "header": {
            "format": "IMAGE",
            "mediaId": "4:MS5qcGc=:aW1hZ2UvanBlZw==:ARbxC3pH-hnOZSObdto4tGAjuB2-INNLk98lRBxGZYLj5XtfKtQjGSzxp0V8fQde-7nmyvbzlpWY2bIvVYvNg8S8SpQyyUueV9xfvbKcPPd7sQ:e:1723555121:564683789153111:100074672771173:ARZ8O5E1vaOJ6415124"
        },
        "body": {
            "text": "Dear {{1}},\nYour {{2}} payment of {{3}} has been processed",
            "examples": [
                "Mary",
                "Funds Transfer",
                "KES 100"
            ]
        },
        "footer": {
            "text": "The Test Bank Team"
        },
        "buttons": [
            {
                "type": "QUICK_REPLY",
                "text": "Ask a Question"
            },
            {
                "type": "QUICK_REPLY",
                "text": "Chat with Support"
            }
        ]
    }
}
```

</details>

<details>

<summary>Request to create an authentication template</summary>

```json
{
    "name": "lipachat_auth_template",
    "language": "en",
    "category": "AUTHENTICATION",
    "component": {
        "body": {
            "addSecurityRecommendation": true // optional
        },
        "footer": {
            "codeExpirationMinutes": 10 // optional
        },
        "buttons": [
            {
                "type": "OTP",
                "otpType": "COPY_CODE",
                "text": "Copy Code"
            }
        ]
    }
}
```

</details>

**Response**

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

```json

{
    "timestamp": null,
    "data": {
        "id": "1661737361284034",
        "status": "APPROVED",
        "category": "MARKETING"
    },
    "status": "success",
    "message": "success",
    "errors": null
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "timestamp": "2024-09-15T20:06:38.675567555",
    "data": null,
    "status": "error",
    "message": "Content in this language already exists",
    "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 %}

### Uploading Template media

When creating a template with media on the header, you should first call the endpoint below to upload media then use the id returned to create the message template.

<mark style="color:green;">`POST`</mark> `https://gateway.lipachat.com/api/v1/template/upload/file`

**Headers**

| Name         | Value                                                                          |
| ------------ | ------------------------------------------------------------------------------ |
| Content-Type | multipart/form-data                                                            |
| apiKey       | Get apiKey from App portal settings tab<https://app.lipachat.com/app/settings> |

**Body**

| Name | Type | Description               |
| ---- | ---- | ------------------------- |
| file | file | Image, video or document. |

**Response**

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

```json
{
    "timestamp": null,
    "data": "4:V2hhdHNBcHAgSW1hZ2UgMjAyNC0wOS0xNSBhdCAxOS4wMS41MC5qcGVn:aW1hZ2UvanBlZw==:ARZi4gxBasbSbhXEXcfZSR7WtrgQCS-xs31BESau0ROb_fh2SFu1xndRAoY41h57QxRDZVsTFF3LyKGKIzxaRMwO_Q0xGZaw9XZ4LNEGqQrWEw:e:1726767043:564683789153111:100074672771173:ARbLETnUSOWfTwBzPfQ",
    "status": "success",
    "message": "success",
    "errors": null
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
use the value of *data* while calling create template endpoint, for templates with media in the header.
{% endhint %}

{% hint style="info" %}
Try out from Postman here [![Run In Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/1880882-362c9de0-8bff-4dbb-9596-194223a41ad8?action=collection%2Ffork\&source=rip_markdown\&collection-url=entityId%3D1880882-362c9de0-8bff-4dbb-9596-194223a41ad8%26entityType%3Dcollection%26workspaceId%3D22009359-4643-460b-b79e-d2fed7c4e868#?env%5BLipachatWhatsappAPI%5D=W3sia2V5IjoiV0FfUEhPTkVfTlVNQkVSIiwidmFsdWUiOiIyNTQxMTAwOTA3NDciLCJlbmFibGVkIjp0cnVlLCJ0eXBlIjoiZGVmYXVsdCIsInNlc3Npb25WYWx1ZSI6IjI1NDExMDA5MDc0NyIsImNvbXBsZXRlU2Vzc2lvblZhbHVlIjoiMjU0MTEwMDkwNzQ3Iiwic2Vzc2lvbkluZGV4IjowfSx7ImtleSI6ImFwaUtleSIsInZhbHVlIjoiIiwiZW5hYmxlZCI6dHJ1ZSwidHlwZSI6ImRlZmF1bHQiLCJzZXNzaW9uVmFsdWUiOiIiLCJjb21wbGV0ZVNlc3Npb25WYWx1ZSI6IiIsInNlc3Npb25JbmRleCI6MX0seyJrZXkiOiJZT1VSX1BIT05FX05VTUJFUiIsInZhbHVlIjoiIiwiZW5hYmxlZCI6dHJ1ZSwidHlwZSI6ImRlZmF1bHQiLCJzZXNzaW9uVmFsdWUiOiIiLCJjb21wbGV0ZVNlc3Npb25WYWx1ZSI6IiIsInNlc3Npb25JbmRleCI6Mn1d)
{% endhint %}


---

# 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/creating-a-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.
