Send a template

SDK platic.messages.sendTemplate()

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

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

Request body

{
  "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"
    }
  }
}
FieldTypeRequiredDescription
channelIdstring✓Sending channel. Prefer the prefixedChannelId (for example wb-123); for compatibility the agent's phone number or legacy channelId are accepted
conversationIdstring✓The contact's phone number in E.164 format without +
responderAgentIdstring—Optional agent that will handle the replies. It does not need to have the sending channel assigned
campaignIdstring—ID of the campaign the message is attributed to. If omitted, the message is recorded under the api campaign
template.namestring✓Name of the template to use
template.languagestring—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
template.paramsarray—Variables for the template body. The count must match the number of variables defined in the template exactly
template.typeenum—Header type: image, document, video. Required if the template has a media header
template.filestring—Public https:// URL of the header file. Required if template.type is present
template.buttonsarray—Dynamic variables of the template's buttons. Maximum 3 elements
delaynumber—Delay in milliseconds (3,000 – 86,400,000; maximum 24 hours)
scheduleTimestring—Scheduled send date/time (ISO 8601). Maximum 30 days after the request
clientobject—Data to create or update the contact's profile

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.

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

FieldTypeRequiredDescription
indexinteger✓0-based index of the button in the template. It must match an existing button
sub_typeenum—url, phone_number, quick_reply, otp. Inferred automatically from the type defined in the template if omitted
parametersarray✓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).
"buttons": [
  {
    "index": 0,
    "parameters": [{ "type": "text", "text": "promo/january" }]
  },
  {
    "index": 1,
    "sub_type": "otp",
    "parameters": [{ "type": "text", "text": "482910" }]
  }
]
FieldTypeDescription
client.namestringFull name of the contact
client.firstnamestringFirst name
client.lastnamestringLast name
client.emailstringEmail address
client.birthdatestringDate of birth (dd/mm/yyyy)
client.genderenumGender: male or female
client.companystringCompany name
client.countryenumISO 3166-1 alpha-2 code (e.g. MX, US)
client.statestringState of residence
client.citystringCity of residence
client.addressstringFull address
client.postalCodestringPostal code
client.customFieldsmapObject with key-value pairs of the custom fields defined in the workspace. See Custom fields for the available ones.
client.ownersarrayEmails of the responsible users

Scheduling

Send the template immediately, with a delay or at a specific date. Afterwards you can read, reschedule or cancel it by messageId.

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

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.
{
  "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:

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

With delay (HTTP 202):

{
  "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):

{
  "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"
}
FieldTypeDescription
messageIdstringID of the created message. For scheduled sends, use it to read, reschedule or cancel the resource; you do not need campaignId or runId
kindenumtemplate in the HTTP 202 responses of this endpoint
statusenumsent, delayed or scheduled
timestampstringDate/time the request was processed (ISO 8601 UTC)
executeAtstringDate/time the message will be sent (ISO 8601 UTC). Only present on delayed or scheduled sends
delayMsnumberConfigured delay in milliseconds. Only present when delay was used
scheduledTimestringOriginal 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 for their statuses and execution rules.

Errors

Statusdetails.codeWhen it happens
400INVALID_REQUESTThe 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)
400INVALID_SCHEDULEdelay 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
400INVALID_REQUESTThe supplied ?workspace= is not authorized for your credential. details.available lists the available workspaces
400INVALID_PHONE_NUMBERThe phone number is not valid
400TEMPLATE_NOT_APPROVEDThe chosen version is not approved: it is PENDING, PAUSED, REJECTED, DISABLED or being deleted. details.status, details.name and details.language say which
401UNAUTHENTICATEDThe credential is missing or invalid
403FORBIDDENThe user does not have access to the workspace, or the session is limited to its own campaign
404TEMPLATE_NOT_FOUNDNo 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
404CHANNEL_NOT_FOUNDNo channel has that channelId. details.channelId repeats it
404RESPONDER_AGENT_NOT_FOUNDThe agent in responderAgentId does not exist
404WORKSPACE_NOT_FOUNDThe credential does not carry any workspace
409CONTACT_BLOCKEDThe contact has status: "blocked". A blocked contact never receives templates
409CHANNEL_UNAVAILABLEThe channel cannot send now. details.channelId says which
409AMBIGUOUS_CHANNELThe channel exists in several workspaces. Add ?workspace=. details.channelId and details.workspaces say which
409RESPONDER_AGENT_INACTIVEThe agent in responderAgentId is not active. details.responderAgentId repeats it
422POST_CONVERSATIONThe channel is a post-comments channel
502UPSTREAM_ERRORThe messaging service failed
503TEMPORARILY_UNAVAILABLEThe 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:

{
  "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.

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: each message has its deliveryStatus.