---
docId: doc_85f2c66748c64c40ae698a6394745dae
title: Send a template
description: "Send an approved WhatsApp template and choose who will handle replies."
api:
  group: mensajes
  auth: bearer
  operations:
    - operationId: sendTemplateMessage
      method: POST
      path: /v1/messages/template
      postmanName: Send a Template Message
---

<script>
  import { Ways, Note, Collapsible } from '$lib/components';
</script>

# Send a template

Send an approved WhatsApp template to a contact. If they have an open conversation, the message is added to it; otherwise, a new one is created. `template.params` must match the number of template variables exactly.


## Example

<Ways tabs="api,sdk">
<Ways.Way name="api">

```bash
curl https://api.platic.ai/v1/messages/template \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "channelId": "wb-123",
    "conversationId": "5215512345678",
    "template": { "name": "order_update", "params": ["1001"] }
  }'
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
await platic.messages.sendTemplate({
  channelId: "wb-123",
  conversationId: "5215512345678",
  template: { name: "order_update", params: ["1001"] },
});
```

</Ways.Way>
</Ways>

## Request body

```json
{
  "channelId": "wb-123456789",
  "conversationId": "521234567890",
  "responderAgentId": "agent_123",
  "campaignId": "pV6PvG2lc8ChQb2VmETr",
  "template": {
    "name": "welcome_customer",
    "language": "es_MX",
    "params": ["Ana", "Premium"],
    "type": "image",
    "file": "https://cdn.assets.com/welcome_image.jpg",
    "buttons": [
      {
        "index": 0,
        "parameters": [{ "type": "text", "text": "promo/january" }]
      }
    ]
  },
  "client": {
    "name": "Ana",
    "customFields": {
      "plate": "ABC123",
      "reception_id": "REC001"
    }
  }
}
```

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `channelId` | string | ✓ | Sending channel. Prefer the `prefixedChannelId` (for example `wb-123`); for compatibility the agent's phone number or legacy channelId are accepted |
| `conversationId` | string | ✓ | The contact's phone number in E.164 format without `+` |
| `responderAgentId` | string | — | Optional agent that will handle the replies. It does not need to have the sending channel assigned |
| `campaignId` | string | — | ID of the campaign the message is attributed to. If omitted, the message is recorded under the `api` campaign |
| `template.name` | string | ✓ | Name of the template to use |
| `template.language` | string | — | The language version to send, such as `es_MX`. Without it, the only one is sent or, if there are several, an approved one; the rule is in [get a template](/api-reference/whatsapp-templates/get#which-version-answers) |
| `template.params` | array | — | Variables for the template body. The count must match the number of variables defined in the template **exactly** |
| `template.type` | enum | — | Header type: `image`, `document`, `video`. Required if the template has a media header |
| `template.file` | string | — | Public `https://` URL of the header file. Required if `template.type` is present |
| `template.buttons` | array | — | Dynamic variables of the template's buttons. Maximum 3 elements |
| `delay` | number | — | Delay in milliseconds (3,000 – 86,400,000; maximum 24 hours) |
| `scheduleTime` | string | — | Scheduled send date/time (ISO 8601). Maximum 30 days after the request |
| `client` | object | — | Data to create or update the contact's profile |

<Note type="tip">

Send `client` to update the profile or create it if it does not exist. The agent can use the new data immediately.

</Note>

### Channel and responder agent

The channel and the agent are independent:

- `channelId` decides which number/channel the message goes out from.
- `responderAgentId` decides which agent handles the replies.
- With a canonical `channelId` and no `responderAgentId`, the new conversation is `initiated` and has no agent. It does not inherit `defaultAgentId`, which is used for incoming messages.
- If you use the legacy identifier (the agent's phone number), that agent is kept.
- If there is no agent, the message is still sent. When the contact replies, the thread becomes `supervised` and stays without AI until you assign an agent.
- If an active conversation already exists for that contact and channel, it keeps its current agent.

<Collapsible summary="Structure of template.buttons">

Each element of the array represents one dynamic button of the template. Static buttons (no variables) do not need to be included.

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `index` | integer | ✓ | 0-based index of the button in the template. It must match an existing button |
| `sub_type` | enum | — | `url`, `phone_number`, `quick_reply`, `otp`. Inferred automatically from the type defined in the template if omitted |
| `parameters` | array | ✓ | Exactly one element with `{ "type": "text", "text": "<value>" }` |

**Important rules:**

- Indexes cannot repeat within the same array.
- For URL buttons, `text` must be a **path segment** (e.g. `"promo/january"`), not a full URL. Sending `"https://..."` returns error 400.
- If `sub_type` is omitted, it is inferred from the type of the button defined in the template (`URL` → `url`, `OTP` → `otp`, `PHONE_NUMBER` → `phone_number`).

```json
"buttons": [
  {
    "index": 0,
    "parameters": [{ "type": "text", "text": "promo/january" }]
  },
  {
    "index": 1,
    "sub_type": "otp",
    "parameters": [{ "type": "text", "text": "482910" }]
  }
]
```

</Collapsible>

<Collapsible summary="Fields of the client object">

| Field | Type | Description |
|-------|------|-------------|
| `client.name` | string | Full name of the contact |
| `client.firstname` | string | First name |
| `client.lastname` | string | Last name |
| `client.email` | string | Email address |
| `client.birthdate` | string | Date of birth (dd/mm/yyyy) |
| `client.gender` | enum | Gender: `male` or `female` |
| `client.company` | string | Company name |
| `client.country` | enum | ISO 3166-1 alpha-2 code (e.g. `MX`, `US`) |
| `client.state` | string | State of residence |
| `client.city` | string | City of residence |
| `client.address` | string | Full address |
| `client.postalCode` | string | Postal code |
| `client.customFields` | map | Object with key-value pairs of the custom fields defined in the workspace. See [Custom fields](/api-reference/custom-fields) for the available ones. |
| `client.owners` | array | Emails of the responsible users |

</Collapsible>

### Scheduling

Send the template immediately, with a delay or at a specific date. Afterwards you can [read, reschedule or cancel it by `messageId`](/api-reference/messages/scheduled).

<Collapsible summary="Scheduling options">

**Delayed send (delay):**

- Minimum: `3000` ms (3 seconds)
- Maximum: `86400000` ms (24 hours)
- Example: `"delay": 5000` sends the message in 5 seconds

**Scheduled send (scheduleTime):**

- ISO 8601 format
- Must be a future date
- Cannot be more than 30 days after the request
- Examples:
  - `"2026-10-15T18:40:00"`: Mexico time (UTC-6)
  - `"2026-10-15T18:40:00Z"`: UTC time
  - `"2026-10-15T18:40:00-06:00"`: with a specific time zone

<Note type="warning">

You cannot use `delay` and `scheduleTime` in the same request.

</Note>

</Collapsible>

### Validation against the template

The API compares the request with the template registered in WhatsApp. If they do not match, it returns `400` with `details.code` `INVALID_REQUEST`.

Each issue appears in `details.issues`. `path` identifies the field; for example, `template.params` is shown as `["template", "params"]`. `expected`, `received` and `example` are included when applicable.

The rules validated automatically are:

- **Number of params:** it must match exactly the number of `{{1}}`, `{{2}}`... variables in the template body.
- **Media header:** if the template has an image, video or document header, `template.type` and `template.file` are required and `type` must match the defined format.
- **Button indexes:** each `index` in `template.buttons` must match an existing button in the template.
- **URL button variables:** the value of `text` must be a path segment, not a full URL.

```json
{
  "code": 400,
  "error": "Bad Request - The request has validation errors",
  "details": {
    "code": "INVALID_REQUEST",
    "message": "Template payload is incompatible with template configuration",
    "template": "welcome_customer",
    "issues": [
      {
        "path": ["template", "params"],
        "message": "The number of params does not match the template definition",
        "expected": 2,
        "received": 1
      },
      {
        "path": ["template", "type"],
        "message": "This template requires media header type",
        "expected": "image",
        "received": null,
        "example": {
          "type": "image",
          "file": "https://example.com/your-media-file"
        }
      }
    ]
  }
}
```

## Response

The response shows whether the template was sent immediately or scheduled.

**Immediate send:**

```json
{
  "messageId": "msg_123xyz",
  "status": "sent",
  "timestamp": "2026-09-20T20:00:00Z"
}
```

**With `delay` (HTTP `202`):**

```json
{
  "messageId": "msg_123xyz",
  "kind": "template",
  "status": "delayed",
  "timestamp": "2026-09-20T20:00:00Z",
  "executeAt": "2026-09-20T20:00:05.000Z",
  "delayMs": 5000
}
```

**With `scheduleTime` (HTTP `202`):**

```json
{
  "messageId": "msg_123xyz",
  "kind": "template",
  "status": "scheduled",
  "timestamp": "2026-09-20T20:00:00Z",
  "executeAt": "2026-10-16T00:40:00.000Z",
  "scheduledTime": "2026-10-15T18:40:00"
}
```

| Field | Type | Description |
|-------|------|-------------|
| `messageId` | string | ID of the created message. For scheduled sends, use it to [read, reschedule or cancel the resource](/api-reference/messages/scheduled); you do not need `campaignId` or `runId` |
| `kind` | enum | `template` in the HTTP `202` responses of this endpoint |
| `status` | enum | `sent`, `delayed` or `scheduled` |
| `timestamp` | string | Date/time the request was processed (ISO 8601 UTC) |
| `executeAt` | string | Date/time the message will be sent (ISO 8601 UTC). Only present on delayed or scheduled sends |
| `delayMs` | number | Configured delay in milliseconds. Only present when `delay` was used |
| `scheduledTime` | string | Original `scheduleTime` value sent in the request. Only present when `scheduleTime` was used |

Sends with `delay` or `scheduleTime` are accepted but not yet sent. See [Scheduled messages](/api-reference/messages/scheduled) for their statuses and execution rules.

## Errors

<Collapsible summary="Show error codes and fixes">

| Status | `details.code` | When it happens |
|--------|----------------|-----------------|
| `400` | `INVALID_REQUEST` | The body is not valid (`details.issues` says which field), `delay` is used together with `scheduleTime`, a button parameter is not valid (`Invalid template button parameter`), or the payload is incompatible with the template (see [Validation against the template](#validation-against-the-template)) |
| `400` | `INVALID_SCHEDULE` | `delay` is out of range, or `scheduleTime` is not valid, is in the past or is more than 30 days ahead. `details.issues` points at `delay` or `scheduleTime` |
| `400` | `INVALID_REQUEST` | The supplied `?workspace=` is not authorized for your credential. `details.available` lists the available workspaces |
| `400` | `INVALID_PHONE_NUMBER` | The phone number is not valid |
| `400` | `TEMPLATE_NOT_APPROVED` | The chosen version is not approved: it is `PENDING`, `PAUSED`, `REJECTED`, `DISABLED` or being deleted. `details.status`, `details.name` and `details.language` say which |
| `401` | `UNAUTHENTICATED` | The credential is missing or invalid |
| `403` | `FORBIDDEN` | The user does not have access to the workspace, or the session is limited to its own campaign |
| `404` | `TEMPLATE_NOT_FOUND` | No template has that name, or it does not have the language in `template.language`. In the second case `details.languages` lists the ones it has |
| `404` | `CHANNEL_NOT_FOUND` | No channel has that `channelId`. `details.channelId` repeats it |
| `404` | `RESPONDER_AGENT_NOT_FOUND` | The agent in `responderAgentId` does not exist |
| `404` | `WORKSPACE_NOT_FOUND` | The credential does not carry any workspace |
| `409` | `CONTACT_BLOCKED` | The contact has `status: "blocked"`. A blocked contact never receives templates |
| `409` | `CHANNEL_UNAVAILABLE` | The channel cannot send now. `details.channelId` says which |
| `409` | `AMBIGUOUS_CHANNEL` | The channel exists in several workspaces. Add `?workspace=`. `details.channelId` and `details.workspaces` say which |
| `409` | `RESPONDER_AGENT_INACTIVE` | The agent in `responderAgentId` is not active. `details.responderAgentId` repeats it |
| `422` | `POST_CONVERSATION` | The channel is a post-comments channel |
| `502` | `UPSTREAM_ERROR` | The messaging service failed |
| `503` | `TEMPORARILY_UNAVAILABLE` | The message could not be queued. Try again |

If there are several versions and you omit `template.language`, an approved version is selected. Send the language to choose a specific version.

A blocked contact answers:

```json
{
  "code": 409,
  "error": "Conflict - The resource state conflicts with this request",
  "details": {
    "code": "CONTACT_BLOCKED",
    "clientId": "client_123",
    "status": "blocked"
  }
}
```

The check is repeated when delayed or scheduled messages run.

</Collapsible>

## Notes

### WhatsApp rules

#### Templates are required

Use an approved template to start the conversation.

#### 24-hour window

After sending the template, wait for the contact to reply before sending free text. You then have a 24-hour window from their last message. Each new message from the contact restarts that window.

#### Delivery limitations

WhatsApp can block messages because of:

- Restrictions in the contact's country
- Numbers in WhatsApp experiments
- Contacts who turned off marketing notifications

#### Check the status

Verify whether your message was delivered:

1. From the platform's inbox.
2. With [the conversation's messages](/api-reference/conversations/messages): each message has its `deliveryStatus`.
