Documentazione ›
Messaggi › Invia template WhatsApp (Meta)
POST
Invia template WhatsApp (Meta)
POSThttps://app.sendapp.ai/api/whatsapp-meta/send
Invia un template approvato tramite la WhatsApp Cloud API di Meta (
type=template). I template servono per iniziare una conversazione o scrivere al cliente fuori dalla finestra di 24 ore. Il template deve essere già approvato da Meta. Vedi Crea template per crearne uno. Le variabili del testo (
{{1}}, {{2}}…) si riempiono con l'array components.Parametri
apikey
obbligatorio
La tua API Key.
token
obbligatorio
Token dell'account.
number
obbligatorio
Numero destinatario in formato internazionale senza + (es. 1234567890).
type
obbligatorio
Deve essere
template.
template.name
obbligatorio
Nome esatto del template approvato.
template.language.code
obbligatorio
Codice lingua del template (es.
it, en_US).
template.components
opzionale
Valori delle variabili del template (body, header, pulsanti). Ometti se il template non ha variabili.
Richiesta
# Template senza variabili
curl -X POST 'https://app.sendapp.ai/api/whatsapp-meta/send' \
-H 'Content-Type: application/json' \
-d '{
"apikey": "YOUR_API_KEY",
"token": "YOUR_ACCOUNT_TOKEN",
"number": "1234567890",
"type": "template",
"template": {
"name": "hello_world",
"language": { "code": "en_US" }
}
}'
# Template con variabili {{1}} e {{2}}
curl -X POST 'https://app.sendapp.ai/api/whatsapp-meta/send' \
-H 'Content-Type: application/json' \
-d '{
"apikey": "YOUR_API_KEY",
"token": "YOUR_ACCOUNT_TOKEN",
"number": "1234567890",
"type": "template",
"template": {
"name": "promo_sconto",
"language": { "code": "it" },
"components": [
{
"type": "body",
"parameters": [
{ "type": "text", "text": "Mario" },
{ "type": "text", "text": "20" }
]
}
]
}
}'<?php
$ch = curl_init('https://app.sendapp.ai/api/whatsapp-meta/send');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'apikey' => 'YOUR_API_KEY',
'token' => 'YOUR_ACCOUNT_TOKEN',
'number' => '1234567890',
'type' => 'template',
'template' => [
'name' => 'promo_sconto',
'language' => ['code' => 'it'],
'components' => [[
'type' => 'body',
'parameters' => [
['type' => 'text', 'text' => 'Mario'],
['type' => 'text', 'text' => '20'],
],
]],
],
]),
]);
echo curl_exec($ch);const res = await fetch('https://app.sendapp.ai/api/whatsapp-meta/send', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
apikey: 'YOUR_API_KEY',
token: 'YOUR_ACCOUNT_TOKEN',
number: '1234567890',
type: 'template',
template: {
name: 'promo_sconto',
language: { code: 'it' },
components: [{
type: 'body',
parameters: [
{ type: 'text', text: 'Mario' },
{ type: 'text', text: '20' }
]
}]
}
})
});
console.log(await res.json());Risposta (200 OK)
{
"status": "success",
"message": "Message sent successfully",
"message_id": "wamid.HBgLMzkxMjM0NTY3ODkwFQIAERgSN0EwMjBBQkZDRDEyMzQ1Njc4"
}Errore
{
"status": "error",
"message": "The template parameters do not match the approved template."
}