# Create a WhatsApp template

POST /v1/whatsapp/templates. Creates a WhatsApp template and submits it to Meta for review, on the WhatsApp Business Account of the workspace's oldest connected number.

`POST https://api.chatwise.so/v1/whatsapp/templates`

Creates a WhatsApp template and submits it to Meta for review, on the WhatsApp Business Account of the workspace's oldest connected number.

Send an `Idempotency-Key` with each new template and reuse it, with the same body, when you retry. A repeat answers 200 with the same template. Without the header, two identical submissions count as a repeat too.

The API key needs the `templates:write` scope. See [authentication and scopes](https://chatwise.so/docs/authentication.md).

## Example

**curl**:

```bash
curl -X POST 'https://api.chatwise.so/v1/whatsapp/templates' \
  -H "Authorization: Bearer $CHATWISE_API_KEY" \
  -H 'Idempotency-Key: order-ready-en-us-v1' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "order_ready",
  "language": "en_US",
  "category": "UTILITY",
  "parameterFormat": "NAMED",
  "components": {
    "body": {
      "text": "Your order {{order_number}} is ready to collect.",
      "examples": {
        "order_number": "A-1042"
      }
    }
  }
}'
```

**Node.js**:

```js
const response = await fetch("https://api.chatwise.so/v1/whatsapp/templates", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.CHATWISE_API_KEY}`,
    "Idempotency-Key": "order-ready-en-us-v1",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "name": "order_ready",
    "language": "en_US",
    "category": "UTILITY",
    "parameterFormat": "NAMED",
    "components": {
      "body": {
        "text": "Your order {{order_number}} is ready to collect.",
        "examples": {
          "order_number": "A-1042"
        }
      }
    }
  }),
});
const body = await response.json();
if (!response.ok) throw new Error(`${response.status}: ${body.message}`);
console.log(body.data);
```

**Python**:

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://api.chatwise.so/v1/whatsapp/templates",
    method="POST",
    headers={
        "Authorization": f"Bearer {os.environ['CHATWISE_API_KEY']}",
        "Idempotency-Key": "order-ready-en-us-v1",
        "Content-Type": "application/json",
    },
    data=json.dumps({
      "name": "order_ready",
      "language": "en_US",
      "category": "UTILITY",
      "parameterFormat": "NAMED",
      "components": {
        "body": {
          "text": "Your order {{order_number}} is ready to collect.",
          "examples": {
            "order_number": "A-1042"
          }
        }
      }
    }).encode(),
)
with urllib.request.urlopen(request) as response:
    print(json.load(response)["data"])
```

## Headers

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key` | string | A key you choose for this template: 1 to 128 letters, digits, dots, underscores, hyphens or colons. |

## Body

JSON. Unknown fields are refused with a 400.

| Field | Type | Description |
| --- | --- | --- |
| `name` | string | **Required.** Lowercase letters, digits and underscores, up to 100 characters. Spaces around it are ignored. |
| `language` | string | **Required.** The language code, such as `en_US`. Each translation is a template of its own. Spaces around it are ignored. |
| `category` | string | **Required.** `UTILITY`, `MARKETING` or `AUTHENTICATION`. |
| `parameterFormat` | string | Only when `category` is `UTILITY` or `MARKETING`. How variables are written: `NAMED` (`{{order_number}}`) or `POSITIONAL` (`{{1}}`). Default: `NAMED`. |
| `components` | object | **Required when `category` is `UTILITY` or `MARKETING`.** What the template contains. |
| `components.header` | object | A text header, or a media header with a sample. |
| `components.header.format` | string | **Required.** The header's kind. One of `TEXT`, `IMAGE`, `VIDEO`, `DOCUMENT`. |
| `components.header.text` | string | **Required when `format` is `TEXT`.** The text, with at most one variable, which can't be at its start or end. Spaces around it are ignored. Can't be blank, or contain NUL characters or unpaired surrogates. At most 60 characters. |
| `components.header.examples` | object | Only when `format` is `TEXT`. A sample value for the variable, by its name or number. At most 100 entries. |
| `components.header.exampleMediaHandle` | string | **Required when `format` is `IMAGE`, `VIDEO`, or `DOCUMENT`.** Meta's handle for a sample file. This API can't create one. Spaces around it are ignored. Can't be blank, or contain NUL characters or unpaired surrogates. At most 2048 characters. |
| `components.body` | object | **Required.** The message. |
| `components.body.text` | string | **Required.** The text. Variables must be inside it, not at its start or end. Spaces around it are ignored. Can't be blank, or contain NUL characters or unpaired surrogates. At most 1024 characters. |
| `components.body.examples` | object | A sample value for each variable, by its name or number. At most 100 entries. |
| `components.footer` | string | Fixed text below the body. Spaces around it are ignored. Can't be blank, or contain NUL characters or unpaired surrogates. At most 60 characters. |
| `components.buttons` | array of objects | Up to 10 buttons. |
| `components.buttons[].type` | string | **Required.** The button's kind. One of `QUICK_REPLY`, `PHONE_NUMBER`, `URL`. |
| `components.buttons[].text` | string | **Required.** The button's label. Spaces around it are ignored. Can't be blank, or contain NUL characters or unpaired surrogates. At most 25 characters. |
| `components.buttons[].phoneNumber` | string | **Required when `type` is `PHONE_NUMBER`.** The number to call: 8 to 15 digits, with or without a `+`. |
| `components.buttons[].url` | string | **Required when `type` is `URL`.** The page to open. It may end with one variable. Spaces around it are ignored. Can't be blank, or contain NUL characters or unpaired surrogates. At most 2000 characters. |
| `components.buttons[].exampleUrl` | string | Only when `type` is `URL`. A complete sample URL, when the URL has a variable. Spaces around it are ignored. Can't be blank, or contain NUL characters or unpaired surrogates. At most 2000 characters. |
| `authentication` | object | **Required when `category` is `AUTHENTICATION`.** Settings of an authentication template. Its text and copy code button are WhatsApp's own. |
| `authentication.codeExpirationMinutes` | integer | **Required.** How long the code is valid, from 1 to 90. |
| `authentication.addSecurityRecommendation` | boolean | Whether to tell the customer not to share the code. Default: `false`. |
| `authentication.buttonText` | string | The copy button's label. Spaces around it are ignored. Can't be blank, or contain NUL characters or unpaired surrogates. At most 25 characters. Default: `Copy Code`. |

## Response

**201.** Submitted to Meta.

```json
{
  "data": {
    "id": "123456789012345",
    "name": "order_ready",
    "language": "en_US",
    "category": "UTILITY",
    "status": "PENDING",
    "rejectionReason": null,
    "sendable": false,
    "parameterFormat": "NAMED",
    "requiresOtp": false,
    "authentication": null,
    "components": {
      "header": null,
      "body": {
        "text": "Your order {{order_number}} is ready to collect.",
        "variables": [
          "order_number"
        ]
      },
      "footer": null,
      "buttons": []
    },
    "unsupportedReason": null,
    "createdAt": "2026-11-19T09:00:00.000Z",
    "updatedAt": "2026-11-19T09:00:00.000Z"
  }
}
```

| Field | Type | Description |
| --- | --- | --- |
| `data.id` | string | The template's id: Meta's, or Chatwise's for an older template without one. Send it as `templateId`. |
| `data.name` | string | The template's name. |
| `data.language` | string | The template's language code, such as `en_US`. |
| `data.category` | string or null | The template's category. |
| `data.status` | string or null | Meta's review status, such as `APPROVED`, `PENDING`, `REJECTED` or `PAUSED`. |
| `data.rejectionReason` | string or null | Why Meta rejected it, when it is rejected. |
| `data.sendable` | boolean | Whether the send routes can send it: approved, with a layout they support. |
| `data.parameterFormat` | string or null | How its variables are written. Null without variables. |
| `data.requiresOtp` | boolean | Whether sending it needs a one-time code, as the `otp` value in `templateParams`. |
| `data.authentication` | object or null | Settings of an authentication template. Otherwise null. |
| `data.authentication.addSecurityRecommendation` | boolean or null | Whether it tells the customer not to share the code. |
| `data.authentication.codeExpirationMinutes` | number or null | How long it says the code is valid. |
| `data.components` | object | What the template contains. |
| `data.components.header` | object or null | The header, if any. |
| `data.components.header.format` | string | `TEXT`, `IMAGE`, `VIDEO` or `DOCUMENT`. |
| `data.components.header.text` | string or null | The text of a text header. |
| `data.components.header.variables` | array of strings | The header's variables. |
| `data.components.body` | object | The body. |
| `data.components.body.text` | string or null | The body's text. |
| `data.components.body.variables` | array of strings | The body's variables. |
| `data.components.footer` | string or null | The footer's text, if any. |
| `data.components.buttons` | array of objects | The buttons. |
| `data.components.buttons[].index` | integer | The button's position, from 0. Use it as `index` when sending. |
| `data.components.buttons[].type` | string | The button's type, such as `URL`, `QUICK_REPLY`, `PHONE_NUMBER`, `COPY_CODE` or `OTP`. |
| `data.components.buttons[].text` | string or null | The button's label. |
| `data.components.buttons[].url` | string or null | The URL of a `URL` button. |
| `data.components.buttons[].phoneNumber` | string or null | The phone number of a `PHONE_NUMBER` button. |
| `data.components.buttons[].variable` | string or null | The variable at the end of a dynamic URL, if any. |
| `data.components.buttons[].parameterType` | string or null | The parameter the button takes when sending, if any. |
| `data.components.buttons[].otpType` | string or null | The kind of one-time code button, on authentication templates. |
| `data.unsupportedReason` | string or null | Why the send routes can't send it, if they can't because of its layout. |
| `data.createdAt` | string | When Chatwise stored the template. ISO 8601, in UTC. |
| `data.updatedAt` | string | When the template last changed in Chatwise. ISO 8601, in UTC. |

**200.** A repeat of an earlier submission, with the template as it is now.

```json
{
  "data": {
    "id": "123456789012345",
    "name": "order_ready",
    "language": "en_US",
    "category": "UTILITY",
    "status": "APPROVED",
    "rejectionReason": null,
    "sendable": true,
    "parameterFormat": "NAMED",
    "requiresOtp": false,
    "authentication": null,
    "components": {
      "header": null,
      "body": {
        "text": "Your order {{order_number}} is ready to collect.",
        "variables": [
          "order_number"
        ]
      },
      "footer": null,
      "buttons": []
    },
    "unsupportedReason": null,
    "createdAt": "2026-11-19T09:00:00.000Z",
    "updatedAt": "2026-11-19T09:05:00.000Z"
  }
}
```

## Errors

| Status | Message | What it means |
| --- | --- | --- |
| 400 | Expected property name or '}' in JSON at position 1 (line 1 column 2) | The request body isn't valid JSON. The message says where. |
| 400 | Validation failed | A parameter or body field is missing, unknown or malformed. `errors` lists each one. |
| 400 | Provide one sample value for each placeholder | The definition breaks one of WhatsApp's template rules. `field` and `message` say which. |
| 400 | Meta rejected the template submission. Check the template details and try again | Meta refused the submission. |
| 401 | A valid Bearer API key is required | The `Authorization` header is missing or isn't `Bearer <API key>`. |
| 401 | Invalid or revoked API key | The key doesn't exist, was revoked, or has expired. |
| 401 | Invalid API key | Chatwise couldn't check the key. Try again. |
| 403 | API key does not have the required scope: templates:write | The key lacks the route's scope. Create a key that has it. |
| 403 | The connected WhatsApp account is not authorized to create templates | The connected WhatsApp account can't create templates. |
| 403 | `WHATSAPP_REAUTH_REQUIRED`: WhatsApp authorization has expired. Ask an administrator to reconnect WhatsApp in Settings. | Meta no longer accepts Chatwise's access to the number. Reconnect it in the dashboard. `reason` is `expired`, `revoked` or `missing`, and the message depends on it. |
| 404 | Active WhatsApp connection not found | Connect a WhatsApp number in the dashboard first. |
| 404 | Template not found | The template this submission created was deleted since. Use a new `Idempotency-Key`. |
| 409 | `TEMPLATE_EXISTS`: A WhatsApp template with this name and language already exists | Use another name, or read the existing template. |
| 409 | `IDEMPOTENCY_KEY_REUSED`: This Idempotency-Key was already used with different template details | Use a new key for a new template. |
| 409 | `TEMPLATE_SUBMISSION_IN_PROGRESS`: A submission for this template name and language is already in progress | A submission of this name and language, with this key or another, is running or unconfirmed. Wait, then repeat the request with the key it was made with. |
| 409 | `TEMPLATE_SUBMISSION_UNCONFIRMED`: Meta has not confirmed this submission. Retry using the same Idempotency-Key | Repeat the request later with the same key and body. If it keeps answering this, Meta doesn't have the template: submit it under another name. |
| 409 | `WHATSAPP_CONNECTION_CHANGED`: The WhatsApp connection changed after this template was submitted | The workspace connected another WhatsApp Business Account since. Submit again with a new key. |
| 413 | request entity too large | The request body is larger than 100 KB. |
| 429 | API key rate limit exceeded | Wait the number of seconds in the `Retry-After` header. |
| 500 | Internal server error | Something failed in Chatwise. Repeat the request with the same key and body. |
| 502 | `WHATSAPP_LOOKUP_FAILED`: Could not check the WhatsApp template submission | Repeat the request with the same key and body. |
| 502 | `TEMPLATE_SUBMISSION_UNCONFIRMED`: The WhatsApp template submission could not be confirmed. Retry using the same Idempotency-Key | Repeat the request with the same key and body. |
| 503 | `WHATSAPP_RATE_LIMITED`: WhatsApp is rate limiting template submissions. Retry with the same Idempotency-Key | Wait, then repeat the request with the same key and body. |

The body of an error is described in [errors](https://chatwise.so/docs/errors.md).
