Send template messages
Message anyone at any time with a template Meta has approved, and fill in names, order numbers and links.
A template is a message you write once and Meta approves. You need one whenever you message someone first, or more than 24 hours after their last message: order updates, reminders, login codes, offers.
Step 1 · Create and get the template approved
Do this once, in the dashboard. Approval usually takes minutes to a few hours. See Template basics.
Step 2 · Find the template's id
/api/v1/templates
Lists your templates with their ids and wording.
curl https://flowleb.com/api/v1/templates \
-H "Authorization: Bearer YOUR_API_KEY"
{
"data": [
{
"id": 31,
"name": "order_shipped",
"category": "UTILITY",
"language": "en",
"header": "Order update",
"body": "Hi {{1}}, your order {{2}} has shipped 🚚 It will reach you by Friday.",
"footer": "Reply STOP to opt out",
…
}
],
"meta": { "count": 1 }
}
Note the id (here 31) and count the {{1}}, {{2}}… placeholders. You fill them in, in that order.
Step 3 · Match your values to the template
Hi {{1}}, your order {{2}} has shipped 🚚 It will reach you by Friday.
- Header Optional. Text, image, video or document.
- Body The message. {{1}} marks a variable.
- Footer Optional small print.
- Buttons Optional. Quick replies, a link or a phone call.
| Template part | Send it as | Example |
|---|---|---|
| Body variables {{1}}, {{2}}… | body: a list, in order | ["Maya", "#2045"] |
| Text header with {{1}} | header_text | "Order #2045" |
| Image, video or document header | header_media_url (a public link) or upload header_media | "https://…/invoice.pdf" |
| Document file name | header_filename | "Invoice-2045.pdf" |
| Link button with a variable | buttons: index (0 = first button), sub_type, value | [{"index":0,"sub_type":"url","value":"2045"}] |
Step 4 · Send it
/api/v1/templates/{id}/send
Sends one template to one number.
curl -X POST https://flowleb.com/api/v1/templates/31/send \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "919876543210",
"body": ["Maya", "#2045"],
"buttons": [ { "index": 0, "sub_type": "url", "value": "2045" } ]
}'
const res = await fetch('https://flowleb.com/api/v1/templates/31/send', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.FLOWLEB_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
to: '919876543210',
body: ['Maya', '#2045'], // {{1}}, {{2}}
buttons: [{ index: 0, sub_type: 'url', value: '2045' }], // fills the button link
}),
});
res = requests.post(
"https://flowleb.com/api/v1/templates/31/send",
headers={"Authorization": "Bearer " + os.environ["FLOWLEB_API_KEY"]},
json={
"to": "919876543210",
"body": ["Maya", "#2045"], # {{1}}, {{2}}
"buttons": [{"index": 0, "sub_type": "url", "value": "2045"}],
},
)
<?php
$ch = curl_init('https://flowleb.com/api/v1/templates/31/send');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('FLOWLEB_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '919876543210',
'body' => ['Maya', '#2045'],
'buttons' => [['index' => 0, 'sub_type' => 'url', 'value' => '2045']],
]),
]);
print_r(json_decode(curl_exec($ch), true));
{
"data": {
"wamid": "wamid.HBgMOTE5ODc2NTQzMjEwFQIAERgS…",
"status": "sent",
"template_id": 31,
"template_name": "order_shipped",
"to": "919876543210"
}
}
Hi Maya, your order #2045 has shipped 🚚 It will reach you by Friday.
Send a document as the header
For invoices, tickets or reports, upload the file in the same request. No separate upload step is needed.
curl -X POST https://flowleb.com/api/v1/templates/44/send \
-H "Authorization: Bearer YOUR_API_KEY" \
-F to=919876543210 \
-F "body[]=Maya" \
-F "body[]=#2045" \
-F header_media=@invoice-2045.pdf \
-F header_filename="Invoice-2045.pdf"