> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getreply.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Sending templates

> Send an approved template to one person.

Templates are the messages you can send any time, also to people who have not written to you. Make and approve them in the app (or with `POST /v1/templates`).

## The request

* `template`: its name and language.
* `body`: one value per variable, in order.
* `header`: a header variable as `text`, or a file header as `media` with an https link.
* `buttons`: a link button's value, a copy-code button's code, or a quick reply's payload, each at its `index`.

```bash cURL theme={null}
curl https://api.getreply.in/v1/messages/template \
  -H "Authorization: Bearer gr_live_…" \
  -H "Idempotency-Key: offer-4521-diwali" \
  -H "Content-Type: application/json" \
  -d '{"to": "+9198250*****", "template": {"name": "diwali_offer", "language": "en"}, "header": {"media": {"type": "image", "url": "https://example.com/offer.jpg"}}, "body": ["Riya", "20%"], "buttons": [{"index": 0, "type": "copy_code", "value": "DIWALI20"}]}'
```

```javascript Node.js theme={null}
const res = await fetch("https://api.getreply.in/v1/messages/template", {
  method: "POST",
  headers: {
    "Authorization": "Bearer gr_live_…",
    "Idempotency-Key": "offer-4521-diwali",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "to": "+9198250*****",
    "template": {
      "name": "diwali_offer",
      "language": "en"
    },
    "header": {
      "media": {
        "type": "image",
        "url": "https://example.com/offer.jpg"
      }
    },
    "body": [
      "Riya",
      "20%"
    ],
    "buttons": [
      {
        "index": 0,
        "type": "copy_code",
        "value": "DIWALI20"
      }
    ]
  }),
});
console.log(await res.json());
```

```php PHP theme={null}
<?php
$ch = curl_init("https://api.getreply.in/v1/messages/template");
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer gr_live_…",
    "Idempotency-Key: offer-4521-diwali",
    "Content-Type: application/json",
  ],
  CURLOPT_POSTFIELDS => '{"to": "+9198250*****", "template": {"name": "diwali_offer", "language": "en"}, "header": {"media": {"type": "image", "url": "https://example.com/offer.jpg"}}, "body": ["Riya", "20%"], "buttons": [{"index": 0, "type": "copy_code", "value": "DIWALI20"}]}',
]);
echo curl_exec($ch);
```

```python Python theme={null}
import requests

res = requests.post(
    "https://api.getreply.in/v1/messages/template",
    headers={
        "Authorization": "Bearer gr_live_…",
        "Idempotency-Key": "offer-4521-diwali",
    },
    json={
        "to": "+9198250*****",
        "template": {
            "name": "diwali_offer",
            "language": "en"
        },
        "header": {
            "media": {
                "type": "image",
                "url": "https://example.com/offer.jpg"
            }
        },
        "body": [
            "Riya",
            "20%"
        ],
        "buttons": [
            {
                "index": 0,
                "type": "copy_code",
                "value": "DIWALI20"
            }
        ]
    },
)
print(res.json())
```

> [!TIP]
>
> Every approved template in the app has an **API example** card with this request already filled in for that template.

## Common errors

* `template_variables_mismatch`: the number of values does not match the template.
* `template_not_approved`: wait until it is approved.
* `contact_stopped`: this person stopped marketing messages.
* `insufficient_balance`: add money to your wallet.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.