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.
Prerequisites
- Active ChatYug API key (
Authorization: Bearer ck_…) - Automation permission enabled on the WABA — portal → Automation settings. Write endpoints return
AUTOMATION_ACCESS_DENIEDwithout it.
Base URL
https://chatyug.com/api/external
Endpoints
| Method | Path | Purpose |
|---|---|---|
| POST | /templates | Create standard text/media template |
| GET | /templates/:templateId/status | Poll Meta approval status |
| POST | /templates/:templateId/sync | Force sync from Meta |
| POST | /templates/carousel | Create carousel template |
Listing approved templates: GET /templates?status=APPROVED — see Send Message for how to use the result.
End-to-end workflow
- Enable Automation on the WABA (portal → Automation settings).
POST /templates— submit template → receivetemplateIdandstatus: "PENDING".- Poll
GET /templates/:templateId/statusevery 2–5 minutes. No webhook is fired when status changes. - (Optional)
POST /templates/:templateId/syncto force a fresh pull from Meta. - When
APPROVED: useGET /templates?status=APPROVEDto list andPOST /send-messageto send.
Request fields — POST /templates
Accepts application/json or multipart/form-data.
| Field | Required | Description |
|---|---|---|
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
}
}
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
| HTTP | Code | When |
|---|---|---|
| 400 | VALIDATION_ERROR | Missing templateName, templateContent, or category; or missing phoneNumberId when uploading mediaFile |
| 403 | AUTOMATION_ACCESS_DENIED | WABA does not have automation permission |
| 404 | TEMPLATE_NOT_FOUND | templateId 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
- List approved templates:
GET /templates?status=APPROVED - Send a template message: Send Message
- Scheduled bulk sends: Scheduled Messages API