A template is a message WhatsApp has approved in advance, and the only kind you can send outside the 24-hour window. You make and submit templates in the app under Messaging > Templates (see Templates); the api lists the approved ones and sends them with your values.
List approved templates
GET https://gdwaapi.grapedawn.tech/api/v1/templates returns every approved template, with what each one needs when you send it.
curl https://gdwaapi.grapedawn.tech/api/v1/templates \
-H "Authorization: Bearer lms_your_key"
[
{
"name": "order_update",
"language": "en",
"category": "UTILITY",
"header": { "format": "IMAGE", "variables": [] },
"body": {
"text": "Hi {{1}}, your order {{2}} has shipped.",
"variables": ["1", "2"]
},
"buttons": [
{
"index": 0,
"type": "URL",
"text": "Track",
"variable": true,
"url": "https://shop.example.com/{{1}}"
},
{
"index": 1,
"type": "QUICK_REPLY",
"text": "Thanks",
"variable": false,
"url": null
}
],
"cards": [],
"unsupported": null
}
]
What a template needs
| Field | What it tells you |
|---|---|
name, language | How to name it when you send it |
header | null, or its format (TEXT, IMAGE, VIDEO, DOCUMENT) and, for a text header, its variables |
body.variables | The body's variables in order: numbers ("1", "2") or names ("first_name") |
buttons | Each button's index (its position from 0) and type. variable is true for a link button whose address ends in a value you give |
cards | For a carousel, each card's index, format (IMAGE or VIDEO) and buttons |
unsupported | null, or the reason the api cannot send it |
A template the api cannot send yet still appears, with unsupported set. That covers carousels whose cards have variables, location headers, catalogue or call buttons, and limited-time offers. Sending one returns a 422 with the same reason.
Fill in a template
Put template in the body of POST https://gdwaapi.grapedawn.tech/api/v1/messages. Give its name, and its language when there is more than one template with that name. Then the values it needs:
| Field | For |
|---|---|
variables | The body's variables, by number or name: {"1": "Asha"} or {"first_name": "Asha"} |
headerVariables | A text header's variable, the same way |
headerMediaUrl | The https:// link of the header's image, video or document |
buttonVariables | A link button's ending, by the button's index: {"0": "orders/1234"} |
couponCode | The code for a copy-code button, up to 15 characters |
cardMediaUrls | A carousel's card files, in card order |
cardButtonVariables | A card link's ending, by "<card>.<button>": {"0.1": "plan-a"} |
Values can be text or numbers. Form buttons, one-time passcode buttons and quick reply buttons need nothing: they are filled in for you.
curl https://gdwaapi.grapedawn.tech/api/v1/messages \
-H "Authorization: Bearer lms_your_key" \
-H "Content-Type: application/json" \
-d '{
"to": "+919800000001",
"template": {
"name": "order_update",
"language": "en",
"headerMediaUrl": "https://shop.example.com/img/parcel.jpg",
"variables": {"1": "Asha", "2": "#1234"},
"buttonVariables": {"0": "orders/1234"}
}
}'
Carousel templates
A carousel sends a row of cards, each with its own picture or video. Give the files in card order:
{
"name": "new_plans",
"language": "en",
"cardMediaUrls": ["https://example.com/a.jpg", "https://example.com/b.jpg"],
"cardButtonVariables": { "0.1": "plan-a", "1.1": "plan-b" }
}
A card you leave out, or give as an empty string, uses the file saved with the template in the app. Every card needs an https:// file one way or the other.
Template errors
A value that is missing or empty is named in a 422, by the field you would put it in:
{
"statusCode": 422,
"message": "Give a value for: variables.2, headerMediaUrl.",
"error": "Unprocessable Entity"
}
A media link that does not start with https:// counts as missing. Other errors:
- 404
There is no approved template called order_update in en.when the name or language is wrong, or the template is not approved yet. - 422
Name the language: en, hi.when the name has more than one language and you gave none. - 422 with the
unsupportedreason, for a template the api cannot send.