Template Creation API

Create and submit WhatsApp message templates to Meta via API key — no portal login required. Templates are always submitted for review immediately; the API returns PENDING. Poll the status endpoint until APPROVED or REJECTED, then send with POST /api/external/send-message.

Prefer the portal UI? Create templates manually at Message Templates → Create Template in the ChatYug portal. The External API is for integrators and automated pipelines.

Prerequisites

  • Active ChatYug API key (Authorization: Bearer ck_…)
  • Automation permission enabled on the WABA — portal → Automation settings. Write endpoints return AUTOMATION_ACCESS_DENIED without it.

Base URL

https://chatyug.com/api/external

Endpoints

MethodPathPurpose
POST/templatesCreate standard text/media template
GET/templates/:templateId/statusPoll Meta approval status
POST/templates/:templateId/syncForce sync from Meta
POST/templates/carouselCreate carousel template

Listing approved templates: GET /templates?status=APPROVED — see Send Message for how to use the result.

End-to-end workflow

  1. Enable Automation on the WABA (portal → Automation settings).
  2. POST /templates — submit template → receive templateId and status: "PENDING".
  3. Poll GET /templates/:templateId/status every 2–5 minutes. No webhook is fired when status changes.
  4. (Optional) POST /templates/:templateId/sync to force a fresh pull from Meta.
  5. When APPROVED: use GET /templates?status=APPROVED to list and POST /send-message to send.

Request fields — POST /templates

Accepts application/json or multipart/form-data.

FieldRequiredDescription
templateName✅Lowercase, underscores. Must be unique in your WABA.
templateContent✅Body text. Use {{1}}, {{2}}, … for variables.
category✅UTILITY, MARKETING, or AUTHENTICATION
language—BCP-47 code. Default: en_US. Common: en, hi, gu
variables—Array of {"index":1,"example":"Rahul"} — one entry per {{n}} placeholder. Required when body has variables.
headerContent—Text header (plain text, no emoji).
footerContent—Footer text (no variables).
buttons—JSON array of button objects. type: QUICK_REPLY, URL, or PHONE_NUMBER.
mediaType—Header media: IMAGE, VIDEO, or DOCUMENT. Requires mediaFile or assetHandle.
mediaFile—Multipart file field (use multipart/form-data). Requires phoneNumberId.
assetHandle—Meta Resumable Upload handle (recommended for VIDEO).
phoneNumberId—Required when uploading mediaFile. Obtain from GET /api/external/me.

Create standard template (text body)

curl -X POST https://chatyug.com/api/external/templates \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "templateName": "order_update_api",
    "templateContent": "Hi {{1}}, your order {{2}} is confirmed.",
    "category": "UTILITY",
    "language": "en",
    "variables": [
      { "index": 1, "example": "Rahul" },
      { "index": 2, "example": "ORD-991" }
    ]
  }'

Response (201 Created)

{
  "success": true,
  "data": {
    "templateId": 128,
    "metaTemplateId": "123456789",
    "status": "PENDING",
    "statusEndpoint": "/api/external/templates/128/status"
  }
}

Create template with media header

Use multipart/form-data and include the mediaFile field. phoneNumberId is required so ChatYug can upload the media to Meta on your behalf.

curl -X POST https://chatyug.com/api/external/templates \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "templateName=promo_with_image" \
  -F "templateContent=Check out our latest offer {{1}}!" \
  -F "category=MARKETING" \
  -F "language=en" \
  -F "mediaType=IMAGE" \
  -F "phoneNumberId=YOUR_PHONE_NUMBER_ID" \
  -F "variables=[{\"index\":1,\"example\":\"Summer Sale\"}]" \
  -F "mediaFile=@/path/to/banner.jpg"

For VIDEO, prefer passing assetHandle (a Meta Resumable Upload handle) in JSON instead of uploading the file via multipart.

Poll approval status

curl -X GET https://chatyug.com/api/external/templates/128/status \
  -H "Authorization: Bearer YOUR_API_KEY"

Response

{
  "success": true,
  "data": {
    "templateId": 128,
    "templateName": "order_update_api",
    "status": "APPROVED",
    "metaStatus": "approved",
    "rejectionReason": null
  }
}
Note: ChatYug does not push a webhook event when template approval status changes. Poll GET /templates/:templateId/status from your integration every 2–5 minutes until the status is no longer PENDING.

Force Meta sync

If the status looks stale, force ChatYug to re-fetch from Meta immediately.

curl -X POST https://chatyug.com/api/external/templates/128/sync \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"phoneNumberId": "YOUR_PHONE_NUMBER_ID"}'

Create carousel template

curl -X POST https://chatyug.com/api/external/templates/carousel \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "phoneNumberId": "YOUR_PHONE_NUMBER_ID",
    "templateName": "summer_sale_carousel",
    "languageCode": "en_US",
    "bodyText": "Swipe to explore our summer collection",
    "cards": [
      {
        "headerSrc": "https://example.com/card1.jpg",
        "bodyText": "T-shirt",
        "buttons": [{ "type": "URL", "text": "Shop", "url": "https://example.com" }]
      },
      {
        "headerSrc": "https://example.com/card2.jpg",
        "bodyText": "Jeans",
        "buttons": [{ "type": "URL", "text": "Shop", "url": "https://example.com/jeans" }]
      }
    ]
  }'

Once APPROVED, send with POST /api/external/messages/carousel.

Error codes

HTTPCodeWhen
400VALIDATION_ERRORMissing templateName, templateContent, or category; or missing phoneNumberId when uploading mediaFile
403AUTOMATION_ACCESS_DENIEDWABA does not have automation permission
404TEMPLATE_NOT_FOUNDtemplateId not in your WABA (status/sync endpoints)
502—Meta rejected the template payload — check message in the response body for Meta's reason

Next steps