Skip to content

Send Template Message

Send a pre-approved WhatsApp message template. Templates can be sent outside the 24-hour messaging window.

POST /api/v1/messages/send

Request

Headers

HeaderRequiredDescription
AuthorizationYesBearer YOUR_API_KEY
Content-TypeYesapplication/json
X-TENANT-IDNoTenant ID (if multi-tenant)

Body Parameters

ParameterTypeRequiredDescription
phonestringYesRecipient phone number with country code
message_typestringYesMust be template
dataobjectYesTemplate data object
data.namestringYesTemplate name (e.g., order_confirmation)
data.language_codestringNoTemplate language code (default: en_US)
data.componentsarrayNoMeta components array with template parameters

Example Request

bash
curl -X POST https://cubeconnect.io/api/v1/messages/send \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "phone": "+966501234567",
    "message_type": "template",
    "data": {
      "name": "order_confirmation",
      "language_code": "en_US",
      "components": [
        {
          "type": "body",
          "parameters": [
            {"type": "text", "text": "ORD-1234"},
            {"type": "text", "text": "500 SAR"}
          ]
        }
      ]
    }
  }'
php
$response = Http::withToken('YOUR_API_KEY')
    ->post('https://cubeconnect.io/api/v1/messages/send', [
        'phone' => '+966501234567',
        'message_type' => 'template',
        'data' => [
            'name' => 'order_confirmation',
            'language_code' => 'en_US',
            'components' => [
                [
                    'type' => 'body',
                    'parameters' => [
                        ['type' => 'text', 'text' => 'ORD-1234'],
                        ['type' => 'text', 'text' => '500 SAR'],
                    ],
                ],
            ],
        ],
    ]);
javascript
const response = await fetch('https://cubeconnect.io/api/v1/messages/send', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    phone: '+966501234567',
    message_type: 'template',
    data: {
      name: 'order_confirmation',
      language_code: 'en_US',
      components: [
        {
          type: 'body',
          parameters: [
            { type: 'text', text: 'ORD-1234' },
            { type: 'text', text: '500 SAR' },
          ],
        },
      ],
    },
  }),
})
python
import requests

response = requests.post(
    'https://cubeconnect.io/api/v1/messages/send',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json',
    },
    json={
        'phone': '+966501234567',
        'message_type': 'template',
        'data': {
            'name': 'order_confirmation',
            'language_code': 'en_US',
            'components': [
                {
                    'type': 'body',
                    'parameters': [
                        {'type': 'text', 'text': 'ORD-1234'},
                        {'type': 'text', 'text': '500 SAR'},
                    ],
                },
            ],
        },
    },
)

Response

Success 202 Accepted

json
{
  "success": true,
  "data": {
    "status": "queued",
    "message_log_id": 4522,
    "conversation_category": "MARKETING",
    "cost": 0.0
  }
}

The conversation_category is determined automatically based on the template's category in Meta Business Manager.

Template Parameters

Templates use positional placeholders like 1, 2, etc. The components array follows the Meta WhatsApp API format.

Example Template

Template name: order_confirmationTemplate body:

Your order {{1}} has been confirmed.
Total amount: {{2}}.
Thank you for your purchase!

API call components:

json
{
  "components": [
    {
      "type": "body",
      "parameters": [
        {"type": "text", "text": "ORD-1234"},
        {"type": "text", "text": "500 SAR"}
      ]
    }
  ]
}

Result sent to customer:

Your order ORD-1234 has been confirmed.
Total amount: 500 SAR.
Thank you for your purchase!

Template Categories

CategoryDescriptionWhen to Use
MARKETINGPromotional contentSales, offers, product announcements
UTILITYTransactional updatesOrder confirmations, shipping updates, account alerts
AUTHENTICATIONOTP and verificationLogin codes, 2FA, verification

Template Without Parameters

If the template has no dynamic parameters, omit the components field:

json
{
  "phone": "+966501234567",
  "message_type": "template",
  "data": {
    "name": "welcome_message",
    "language_code": "en_US"
  }
}

Common Errors

ErrorCause
Template not foundThe template name doesn't exist or hasn't been approved
Parameter count mismatchThe number of parameters in components doesn't match the template's placeholders
Template pausedMeta has paused the template due to quality issues

Template Approval

Templates must be approved by Meta before they can be sent. Create and manage templates from the CubeConnect dashboard under Templates.

CubeConnect WhatsApp Business Platform