Template Message
A WhatsApp template is required to send messages outside the 24-hour window (conversation opener). The template must be in APPROVED status in Meta before it can be used.
Manage templates on the cpaas.id page Message Template.
Request Body
Section titled “Request Body”Template with Text Parameters
Section titled “Template with Text Parameters”{ "messaging_product": "whatsapp", "to": "6281234567890", "type": "template", "template": { "name": "order_confirmation", "language": { "code": "id" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "John Doe" }, { "type": "text", "text": "ORD-12345" } ] } ] }}Field template
Section titled “Field template”| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Template name (must already be APPROVED) |
language | object | Yes | Language object with the code |
components | array | No | Array of dynamic components (header, body, button) |
Field language
Section titled “Field language”| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Language/locale code, e.g. "id", "en_US", "en" |
Field components[]
Section titled “Field components[]”| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Component type: "header", "body", "button" |
parameters | array | No | Dynamic parameters for this component |
sub_type | string | No | Sub-type for button: "url", "quick_reply" |
index | string/number | No | Button index (0-based), for component button |
Parameter Type
Section titled “Parameter Type”Each parameter in parameters has a field type:
| Type | Example | Description |
|---|---|---|
text | { "type": "text", "text": "John" } | Text parameters |
image | { "type": "image", "image": { "link": "..." } } | Image in header |
document | { "type": "document", "document": { "link": "..." } } | Document in header |
currency | { "type": "currency", "currency": { "fallback_value": "Rp 150.000", "code": "IDR", "amount_1000": 150000000 } } | Currency value |
coupon_code | { "type": "coupon_code", "coupon_code": "DISKON50" } | Coupon code |
Example: Template with a URL Button
Section titled “Example: Template with a URL Button”{ "messaging_product": "whatsapp", "to": "6281234567890", "type": "template", "template": { "name": "payment_reminder", "language": { "code": "id" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "Budi Santoso" }, { "type": "currency", "currency": { "fallback_value": "Rp 250.000", "code": "IDR", "amount_1000": 250000000 } } ] }, { "type": "button", "sub_type": "url", "index": "0", "parameters": [ { "type": "text", "text": "INV-2026-001" } ] } ] }}Complete Example (Simple Template)
Section titled “Complete Example (Simple Template)”curl -X POST https://messaging.cpaas.id/v1/YOUR_PHONE_NUMBER_ID/messages \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "messaging_product": "whatsapp", "to": "6281234567890", "type": "template", "template": { "name": "order_confirmation", "language": { "code": "id" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "John Doe" }, { "type": "text", "text": "ORD-12345" } ] } ] } }'import requests
url = "https://messaging.cpaas.id/v1/YOUR_PHONE_NUMBER_ID/messages"headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json"}payload = { "messaging_product": "whatsapp", "to": "6281234567890", "type": "template", "template": { "name": "order_confirmation", "language": {"code": "id"}, "components": [ { "type": "body", "parameters": [ {"type": "text", "text": "John Doe"}, {"type": "text", "text": "ORD-12345"} ] } ] }}
response = requests.post(url, json=payload, headers=headers)print(response.json())const response = await fetch( 'https://messaging.cpaas.id/v1/YOUR_PHONE_NUMBER_ID/messages', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json', }, body: JSON.stringify({ messaging_product: 'whatsapp', to: '6281234567890', type: 'template', template: { name: 'order_confirmation', language: { code: 'id' }, components: [ { type: 'body', parameters: [ { type: 'text', text: 'John Doe' }, { type: 'text', text: 'ORD-12345' }, ], }, ], }, }), });const data = await response.json();console.log(data);Response
Section titled “Response”{ "messaging_product": "whatsapp", "messages": [ { "id": "msg_f7a816e2-8397-11f0-8e34-010203040506" } ]}Webhook Statuses You Will Receive
Section titled “Webhook Statuses You Will Receive”message.status.sent— Template was sent successfullymessage.status.delivered— Template reached the recipient’s devicemessage.status.read— Template was read by the recipient
In addition, you can also receive events related to the status of the template itself:
| The | Description |
|---|---|
template_status_update | Template status changes (APPROVED, REJECTED, PENDING) |
template_quality_update | Template quality update |
template_category_update | Template category change by Meta |
See the page Webhook for details on the payload format of each event.