Skip to content
Chatwise
Skip to Content
Developer docs

Send a template by id

POST /v1/messages. Sends an approved WhatsApp template by its id.

View as Markdown

POSThttps://api.chatwise.so/v1/messages

Sends an approved WhatsApp template by its id. The answer means WhatsApp accepted the message, not that it was delivered.

This route only sends WhatsApp templates. With another channel, or without templateId, it answers 201 and sends nothing.

Sending twice sends two messages. After a timeout or a 500 the message may have been sent, so check before you retry.

The API key needs the messages:send scope. See authentication and scopes.

Example

curl -X POST 'https://api.chatwise.so/v1/messages' \
  -H "Authorization: Bearer $CHATWISE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "to": "12025550147",
  "channel": "WHATSAPP",
  "templateId": "123456789012345",
  "templateParams": [
    {
      "parameter_name": "order_number",
      "text": "A-1042"
    }
  ]
}'

Body

JSON. Unknown fields are refused with a 400.

FieldTypeDescription
tostringRequired. The customer's phone number with its country code.
templateIdstringThe template's id. Needed to send.
templateParamsarray of objectsValues for the body's variables. A template with a variable or media in its header, a dynamic URL button or a copy code button takes templateComponents instead. Keys other than parameter_name and text are ignored.
templateParams[].parameter_namestringRequired. The variable's name, its number (1, 2, …), or otp for the code of an authentication template.
templateParams[].textstringRequired. The variable's value.
templateLanguagestringThe language code to send it in, such as en_US. Without it, the template's own. Spaces around it are ignored.
templateComponentsarray of objectsValues for the header, body and buttons, up to 12 components. Used instead of templateParams, except for authentication templates. At most one header and one body, and no two buttons with the same subType and index.
templateComponents[].typestringRequired. header, body or button.
templateComponents[].parametersarray of objectsRequired. The component's values: one for a header or a button, one or more for a body.
templateComponents[].parameters[].typestringRequired. The kind of value. One of text, image, video, document, currency, date_time, payload, coupon_code.
templateComponents[].parameters[].textstringRequired when type is text. The text.
templateComponents[].parameters[].parameterNamestringOnly when type is text, currency, or date_time. The variable's name, for templates with named variables. Spaces around it are ignored. Can't be blank. At most 64 characters.
templateComponents[].parameters[].imageobjectRequired when type is image and templateComponents[].type is header. An image, by link or Meta media id. Needs link or id.
templateComponents[].parameters[].image.linkstringThe image's public URL.
templateComponents[].parameters[].image.idstringThe image's Meta media id. Spaces around it are ignored. Can't be blank.
templateComponents[].parameters[].videoobjectRequired when type is video and templateComponents[].type is header. A video, by link or Meta media id. Needs link or id.
templateComponents[].parameters[].video.linkstringThe video's public URL.
templateComponents[].parameters[].video.idstringThe video's Meta media id. Spaces around it are ignored. Can't be blank.
templateComponents[].parameters[].documentobjectRequired when type is document and templateComponents[].type is header. A document, by link or Meta media id. Needs link or id.
templateComponents[].parameters[].document.linkstringThe document's public URL.
templateComponents[].parameters[].document.idstringThe document's Meta media id. Spaces around it are ignored. Can't be blank.
templateComponents[].parameters[].document.filenamestringThe file name the customer sees. At most 240 characters.
templateComponents[].parameters[].currencyobjectRequired when type is currency and templateComponents[].type is body. An amount of money.
templateComponents[].parameters[].currency.fallbackValuestringRequired. The amount as text, such as $12.50.
templateComponents[].parameters[].currency.codestringRequired. The ISO 4217 currency code. Spaces around it are ignored.
templateComponents[].parameters[].currency.amount1000integerRequired. The amount times 1000.
templateComponents[].parameters[].dateTimeobjectRequired when type is date_time and templateComponents[].type is body. A date or time.
templateComponents[].parameters[].dateTime.fallbackValuestringRequired. The date or time as text.
templateComponents[].subTypestringRequired when type is button. The button's kind: url takes a text parameter, quick_reply a payload, copy_code a coupon_code.
templateComponents[].indexintegerRequired when type is button. The button's position, from 0.
templateComponents[].parameters[].payloadstringRequired when type is payload and templateComponents[].type is button. What a quick reply button sends back. At most 256 characters.
templateComponents[].parameters[].couponCodestringRequired when type is coupon_code and templateComponents[].type is button. The code a copy code button copies. At most 15 characters.
channelstringRequired. Use WHATSAPP. One of WHATSAPP, INSTAGRAM.
fromstringThe connected WhatsApp number to send from, digits only. Without it: the number on the template's WhatsApp Business Account the customer last wrote to, else the oldest number there.

Response

201. WhatsApp accepted the message.

{
  "data": {
    "message": "Message accepted",
    "from": "+1 202-555-0199"
  }
}
FieldTypeDescription
data.messagestringA confirmation.
data.fromstringThe WhatsApp number it was sent from. Absent when nothing was sent.

Errors

StatusMessageWhat it means
400Expected property name or '}' in JSON at position 1 (line 1 column 2)The request body isn't valid JSON. The message says where.
400Validation failedA parameter or body field is missing, unknown or malformed. errors lists each one.
400Template must be approved to send messagesMeta hasn't approved the template, or paused or rejected it.
400This template is on a different WhatsApp Business Account from the number in fromUse a from number on the template's WhatsApp Business Account.
400An OTP code is required for authentication templatesSend the code as templateParams with parameter_name set to otp.
400Numbered template variables must start at 1 and include each position onceNumber the variables from 1, each once.
400That WhatsApp number is not connected to this workspaceUse one of the workspace's connected numbers, digits only. data.accounts lists them.
401A valid Bearer API key is requiredThe Authorization header is missing or isn't Bearer <API key>.
401Invalid or revoked API keyThe key doesn't exist, was revoked, or has expired.
401Invalid API keyChatwise couldn't check the key. Try again.
402ADMIN_SERVICES_BLOCKED: Chatwise services have been paused for this workspace by an administrator. Contact support to restore service.Sending is paused for the workspace. Contact support.
403API key does not have the required scope: messages:sendThe key lacks the route's scope. Create a key that has it.
403WHATSAPP_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.
404Template not foundNo such template in the key's workspace. Sending by name finds approved templates only.
404Whatsapp account not foundThe workspace has no connected WhatsApp number.
404No connected WhatsApp number on this template's business accountConnect a number on the template's WhatsApp Business Account.
413request entity too largeThe request body is larger than 100 KB.
429API key rate limit exceededWait the number of seconds in the Retry-After header.
500Internal server error: WhatsApp send failed: 400 {"error":{"message":"(#132000) Number of parameters does not match the expected number of params"}}WhatsApp didn't accept the message. The number is Meta's HTTP status, and after it comes Meta's answer when that was JSON. A 429 can be tried later, after a 5xx check first, and for other statuses fix what the answer names.
500Internal server errorSomething failed in Chatwise. The message may have been sent, even if it isn't in the conversation. Quote errorId to support.

The body of an error is described in errors.

On this page