Skip to the content.

Submit WhatsApp template

Generate the Meta API payload for a stored template and submit it for approval.

Endpoint: POST https://<base>/api/v2/CreateWhatsappTemplate.php

Takes a template stored in the Velip database (cc_wa_templates) and submits it to the Meta Cloud API for review/approval. The endpoint builds the JSON payload, optionally swaps a media handle for a public URL, and writes both the original payload (cwt_meta_json) and the URL-rewritten copy (cwt_meta_json_with_urls) back to the database.

This is the API used by the Velip portal’s “Submit template” button — you typically don’t need to call it directly unless you are bypassing the portal.

Authentication

Token authentication required. See Authentication.

Request

tsid — type: stringrequired

Token for the account.

template_id — type: integerrequired

ID of the template row in cc_wa_templates (cwt_id). Must belong to the authenticated customer and the supplied line.

app_id — type: integerrequired

ID of the WhatsApp line (cd_v8_line.v8l_id). Must be an active line with v8l_wa_provider='meta'.

action — type: stringrequired

Operation to perform. Currently only create is exercised end-to-end (Meta does not allow direct template editing).

cwm_id — type: integer

Optional id of an entry in cc_wa_media. When supplied, its cwm_file_path (a public URL) replaces the header_handle in the JSON saved to cwt_meta_json_with_urls. The version sent to Meta keeps the original handle.

Behavior

  1. Loads the template row from cc_wa_templates.
  2. Loads the line credentials from cd_v8_line (v8l_wa_api_key, v8l_wa_business_id).
  3. Validates required fields: cwt_name, cwt_category, cwt_language, cwt_body_text. If the template uses placeholders (1, 2, …) it also requires cwt_variables_examples.
  4. Builds the Meta payload (name, category, language, components[]).
  5. Saves both the original and URL-substituted JSON in the database.
  6. Submits the payload via POST https://graph.facebook.com/v22.0/{business_id}/message_templates.
  7. Updates cwt_status and cwt_template_id (Meta-side id) on success, or cwt_status='REJECTED' plus cwt_rejection_reason on failure.

Request example

```bash curl curl -X POST ‘https:///api/v2/CreateWhatsappTemplate.php’
-H ‘Content-Type: application/json’
-d ‘{ “tsid”: “YOUR_TSID”, “template_id”: 123, “app_id”: 1234, “action”: “create” }’

## Response
```json 201 Created
{
  "return": {
    "status": "OK",
    "status_code": "0",
    "template_id": "123",
    "meta_template_id": "456789012345678",
    "meta_status": "OK",
    "json_generated": "{...}",
    "meta_raw_response": "{...}"
  }
}

json 400 Validation { "return": { "status": "No app name", "status_code": "232", "template_id": "123", "meta_template_id": "", "meta_status": "ERROR", "json_generated": null, "meta_raw_response": "" } }

Error codes

Code status Cause
230 No template_id Missing or invalid template_id.
231 Only Meta provider supported Line’s v8l_wa_provider is not meta.
232 No app name v8l_wa_app_name empty on the line.
233 No API key v8l_wa_api_key empty on the line.
234 Business ID not configured v8l_wa_business_id missing.
235 Meta config not found Line not found, inactive, or wrong customer.
236 No app_id Missing app_id.
237 No action Missing action parameter.
238 Template not found template_id does not belong to the customer/line.
239 Failed to load template data Database error after the template row matched.
240243 Empty required field One of cwt_name, cwt_category, cwt_language, or cwt_body_text is empty.
245 Failed to generate JSON The payload could not be encoded as JSON.
247250 Variables / examples error Template uses placeholders but cwt_variables_examples is missing/invalid.
260 Meta API error Meta rejected the template; full message is in meta_raw_response and stored on cwt_rejection_reason.

Warning Approval is asynchronous. A 200 OK here only means the template was accepted for review. Use CheckTemplateStatus to poll the actual status (APPROVED, REJECTED, PENDING).