---
title: "Send a WhatsApp template via the API"
description: "Send an approved WhatsApp template via POST /api/v1/templates: parameters, variables format, cURL example and common errors."
url: https://help.getkanal.com/en/articles/15-send-a-whatsapp-template-via-the-api
collection: "API"
updated: 2026-11-13
language: en
alternates: [fr-fr]
---

# Send a WhatsApp template via the API

Send an approved WhatsApp template via POST /api/v1/templates: parameters, variables format, cURL example and common errors.

Sending a template is the only way to contact a customer first on WhatsApp, that is, outside the 24-hour conversation window. The template must be approved by Meta before any send.

The complete and always up-to-date reference for this endpoint is available on [developers.getkanal.com](https://developers.getkanal.com/docs/messaging/send-template).

## Endpoint

```text
POST https://api.getkanal.com/api/v1/templates
```

This endpoint requires an active subscription. It is limited to **60 requests per minute** per API key: it is the only API endpoint subject to this limit.

## Headers

-   `Authorization: Bearer <YOUR_API_KEY>`
    
-   `Content-Type: application/json`
    
-   `Idempotency-Key` (optional): replaying a request with the same key does not send the message a second time. Use a unique value, for example a UUID: a key already known to Kanal is treated as a duplicate and the message is not sent.
    

> **Warning:** **After an error, change the Idempotency-Key.** If a first send failed, a new attempt with the same `Idempotency-Key` answers that the message was already sent, although nothing went out. Use a new key for each new attempt after an error.

## Parameters

<table style="min-width: 75px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p><strong>Field</strong></p></th><th colspan="1" rowspan="1"><p><strong>Type</strong></p></th><th colspan="1" rowspan="1"><p><strong>Description</strong></p></th></tr><tr><td colspan="1" rowspan="1"><p><code>template_id</code></p></td><td colspan="1" rowspan="1"><p>integer, required</p></td><td colspan="1" rowspan="1"><p>The identifier of the template to send.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>phone_number</code></p></td><td colspan="1" rowspan="1"><p>string, required</p></td><td colspan="1" rowspan="1"><p>The recipient's number, including the country code. Non-numeric characters are ignored.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>variables</code></p></td><td colspan="1" rowspan="1"><p>object, conditional</p></td><td colspan="1" rowspan="1"><p>Required if the template contains variables. Flat object: each key is the name of a template variable, each value is a string.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>cleanForCountry</code></p></td><td colspan="1" rowspan="1"><p>string, optional</p></td><td colspan="1" rowspan="1"><p>With the value "FR", removes the leading 0 and adds the 33 country code if it is missing.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>name</code></p></td><td colspan="1" rowspan="1"><p>string, optional</p></td><td colspan="1" rowspan="1"><p>Name given to the contact when it is created. Defaults to "Unknown".</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>email</code></p></td><td colspan="1" rowspan="1"><p>string, optional</p></td><td colspan="1" rowspan="1"><p>Email given to the contact when it is created.</p></td></tr></tbody></table>

> **Info:** **Header media.** The header image, video or document always comes from the template. There is no parameter to replace it in the request: to change the media, edit the template in Kanal.

## Variables format

The `variables` field is an **object** whose keys are the **names** of the variables declared in the template, not an ordered array. Kanal then builds the WhatsApp payload server-side.

```json
{
  "first_name": "Jane",
  "order_id": "10456"
}
```

> **Warning:** **Values must always be strings.** Write `"10456"`, not `10456`. A numeric value is rejected by Meta (error 100, "expected \[string, null\]") and the message is not sent.

**Dynamic URL button**: its variable uses the **button text** as its key, as it appears in the template. The button takes its URL from this variable. Static URL buttons and quick reply buttons need no variable.

```json
{
  "first_name": "Jane",
  "Track my order": "https://example.com/orders/10456"
}
```

## Finding your template\_id

-   Call `GET /api/v1/get_templates` to list your approved templates and their identifiers.
    
-   Or click your team name, then **Settings** > **WhatsApp Templates**, and open the template: the identifier is at the end of the URL.
    

Every approved template of your number can be sent through the API, including those created in an automation or a campaign. You can also create a template dedicated to the API in **Settings > WhatsApp Templates**, but this is not required.

## Example request

```bash
curl -X POST https://api.getkanal.com/api/v1/templates \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 6f1c2a9e-0b4d-4c1e-9a7f-3d2b1e0c5a88" \
  -d '{
    "template_id": 1234,
    "phone_number": "+33612345678",
    "name": "Jane Doe",
    "variables": { "first_name": "Jane", "order_id": "10456" }
  }'
```

## Response

Success response (`200`):

```json
{
  "success": true,
  "message": "Template message sent successfully",
  "message_id": 987654,
  "contact_id": 54321,
  "phone_number": "33612345678"
}
```

If the same `Idempotency-Key` is replayed, the API returns a `201` with the message `Message already sent with this idempotency key`, without sending the message again. This also happens if the first send had failed: after an error, use a new key.

## Common errors

<table style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p><strong>Code</strong></p></th><th colspan="1" rowspan="1"><p><strong>Cause</strong></p></th></tr><tr><td colspan="1" rowspan="1"><p><code>401</code></p></td><td colspan="1" rowspan="1"><p>Missing or invalid API key.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>403</code></p></td><td colspan="1" rowspan="1"><p>The team has no active subscription.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>404</code></p></td><td colspan="1" rowspan="1"><p>Template not found for this number.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>429</code></p></td><td colspan="1" rowspan="1"><p>More than 60 requests per minute with the same key. The response contains <code>retry_after: 60</code>: wait 60 seconds before retrying.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>400</code></p></td><td colspan="1" rowspan="1"><p>Missing parameter, invalid number, opted-out contact, missing template variable (<code>Variable &lt;name&gt; not found in row</code>) or value rejected by Meta, for example a number instead of a string.</p></td></tr></tbody></table>
