API
Modelli
Elenca e invia modelli di messaggio di WhatsApp approvati
# Modelli > Elenca e invia modelli di messaggio di WhatsApp approvati - Pagina: https://tbit.app/it/docs/api/templates - URL base: `https://rest-api.tbit.app/v1` - Autenticazione: header `X-API-Key` con la tua chiave in ogni richiesta (gli esempi la leggono dalla variabile d'ambiente `TBIT_API_KEY`) ## Panoramica I modelli sono formati di messaggio di WhatsApp pre-approvati, necessari per avviare conversazioni fuori dalla finestra di messaggistica di 24 ore. Si possono inviare solo i modelli con stato approvato da Meta. ## Endpoint | Metodo | Percorso | Descrizione | | --- | --- | --- | | `GET` | `/v1/templates` | Elenca i modelli di WhatsApp approvati | | `GET` | `/v1/templates/:id` | Dettaglio di un modello | | `POST` | `/v1/templates/:id/send` | Invia un modello a un contatto | | `GET` | `/v1/channels/:channel_id/templates` | Modelli approvati di una linea WhatsApp | | `GET` | `/v1/campaigns/:key/executions` | Stato di consegna per destinatario (invii fatti con una chiave di campagna) | ## Elencare i modelli `GET /v1/templates` ```bash curl "https://rest-api.tbit.app/v1/templates" \ -H "X-API-Key: $TBIT_API_KEY" ``` ## Ottenere il dettaglio di un modello `GET /v1/templates/tpl_abc123` ```bash curl "https://rest-api.tbit.app/v1/templates/tpl_abc123" \ -H "X-API-Key: $TBIT_API_KEY" ``` ## Modelli per linea WhatsApp Un modello viene approvato su un solo account WhatsApp Business, quindi un agente con più linee ha un insieme di modelli per ogni linea. GET /v1/templates mescola tutte le linee (ogni elemento porta il suo channel_id); usa questo endpoint per elencare solo quello che una linea può inviare. L'id del canale è quello che vedi in Piattaforma → Canali. `GET /v1/channels/6a7268abec6ecaf999a6c0ba/templates` ```bash curl "https://rest-api.tbit.app/v1/channels/6a7268abec6ecaf999a6c0ba/templates" \ -H "X-API-Key: $TBIT_API_KEY" ``` ## Inviare un modello Nota sull'invio L'array dei componenti segue il formato dell'API di WhatsApp Business. Includi i componenti di intestazione, corpo e pulsanti secondo quanto richiede il tuo modello. `POST /v1/templates/tpl_abc123/send` ```bash curl -X POST "https://rest-api.tbit.app/v1/templates/tpl_abc123/send" \ -H "X-API-Key: $TBIT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": "573001234567", "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "John" }, { "type": "text", "text": "your order #1234" } ] } ] }' ``` ## Stato di consegna La risposta dell'invio significa solo che Meta HA ACCETTATO il messaggio; consegnato / letto / non riuscito arrivano qualche minuto dopo tramite i webhook di Meta. Per leggerli, passa `campaign` {key, name} nel body dell'invio (l'invio resta registrato sotto quella chiave, visibile anche in Piattaforma → Campagne) e interroga questo endpoint. `status` è sent, delivered, read o failed; `message_id` è il wamid che restituisce l'invio (arriva anche nella risposta dell'invio). `GET /v1/campaigns/my-app/executions` ```bash curl "https://rest-api.tbit.app/v1/campaigns/my-app/executions?since=2026-08-27T00:00:00Z&limit=100" \ -H "X-API-Key: $TBIT_API_KEY" ``` Risposta: ```json { "data": [ { "id": "6a90ea1f...", "to": "573001234567", "template_id": "tpl_abc123", "message_id": "wamid.HBgLNTcz...", "status": "failed", "error_message": "This message was not delivered to maintain healthy ecosystem engagement.", "sent_at": "2026-08-28T02:17:59.494Z", "delivered_at": null, "read_at": null } ] } ``` ## Formato della risposta Un oggetto modello: ```json { "data": [ { "id": "tpl_abc123", "name": "order_confirmation", "language": "es", "status": "APPROVED", "category": "UTILITY", "channel_id": "6a7268abec6ecaf999a6c0ba", "components": [ { "type": "BODY", "text": "Hola {{1}}, {{2}} ha sido confirmado." } ], "created_at": "2024-08-15T10:00:00Z" } ] } ``` ## Risposta dell'invio Un invio riuscito restituisce l'ID del messaggio: ```json { "data": { "message_sent": true, "message_id": "wamid.HBgLNTczMDAxMjM0NTY3FQIAERgSMUY2RUZGM0Y3RTJCRTQ5AA==", "parsed_message": "Hola John, your order #1234 ha sido confirmado." } } ```I modelli sono formati di messaggio di WhatsApp pre-approvati, necessari per avviare conversazioni fuori dalla finestra di messaggistica di 24 ore. Si possono inviare solo i modelli con stato approvato da Meta.
| Metodo | Percorso | Descrizione |
|---|---|---|
| GET | /v1/templates | Elenca i modelli di WhatsApp approvati |
| GET | /v1/templates/:id | Dettaglio di un modello |
| POST | /v1/templates/:id/send | Invia un modello a un contatto |
| GET | /v1/channels/:channel_id/templates | Modelli approvati di una linea WhatsApp |
| GET | /v1/campaigns/:key/executions | Stato di consegna per destinatario (invii fatti con una chiave di campagna) |
/v1/templatescurl "https://rest-api.tbit.app/v1/templates" \
-H "X-API-Key: $TBIT_API_KEY"const response = await fetch('https://rest-api.tbit.app/v1/templates', {
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
},
});
const data = await response.json();import axios from 'axios';
const { data } = await axios.get(
'https://rest-api.tbit.app/v1/templates',
{
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
},
},
);import os
import requests
response = requests.get(
'https://rest-api.tbit.app/v1/templates',
headers={'X-API-Key': os.environ['TBIT_API_KEY']},
)
data = response.json()<?php
$ch = curl_init('https://rest-api.tbit.app/v1/templates');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . getenv('TBIT_API_KEY'),
],
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);/v1/templates/tpl_abc123curl "https://rest-api.tbit.app/v1/templates/tpl_abc123" \
-H "X-API-Key: $TBIT_API_KEY"const response = await fetch('https://rest-api.tbit.app/v1/templates/tpl_abc123', {
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
},
});
const data = await response.json();import axios from 'axios';
const { data } = await axios.get(
'https://rest-api.tbit.app/v1/templates/tpl_abc123',
{
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
},
},
);import os
import requests
response = requests.get(
'https://rest-api.tbit.app/v1/templates/tpl_abc123',
headers={'X-API-Key': os.environ['TBIT_API_KEY']},
)
data = response.json()<?php
$ch = curl_init('https://rest-api.tbit.app/v1/templates/tpl_abc123');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . getenv('TBIT_API_KEY'),
],
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);Un modello viene approvato su un solo account WhatsApp Business, quindi un agente con più linee ha un insieme di modelli per ogni linea. GET /v1/templates mescola tutte le linee (ogni elemento porta il suo channel_id); usa questo endpoint per elencare solo quello che una linea può inviare. L'id del canale è quello che vedi in Piattaforma → Canali.
/v1/channels/6a7268abec6ecaf999a6c0ba/templatescurl "https://rest-api.tbit.app/v1/channels/6a7268abec6ecaf999a6c0ba/templates" \
-H "X-API-Key: $TBIT_API_KEY"const response = await fetch('https://rest-api.tbit.app/v1/channels/6a7268abec6ecaf999a6c0ba/templates', {
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
},
});
const data = await response.json();import axios from 'axios';
const { data } = await axios.get(
'https://rest-api.tbit.app/v1/channels/6a7268abec6ecaf999a6c0ba/templates',
{
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
},
},
);import os
import requests
response = requests.get(
'https://rest-api.tbit.app/v1/channels/6a7268abec6ecaf999a6c0ba/templates',
headers={'X-API-Key': os.environ['TBIT_API_KEY']},
)
data = response.json()<?php
$ch = curl_init('https://rest-api.tbit.app/v1/channels/6a7268abec6ecaf999a6c0ba/templates');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . getenv('TBIT_API_KEY'),
],
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);Nota sull'invio
L'array dei componenti segue il formato dell'API di WhatsApp Business. Includi i componenti di intestazione, corpo e pulsanti secondo quanto richiede il tuo modello.
/v1/templates/tpl_abc123/sendcurl -X POST "https://rest-api.tbit.app/v1/templates/tpl_abc123/send" \
-H "X-API-Key: $TBIT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "573001234567",
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "John"
},
{
"type": "text",
"text": "your order #1234"
}
]
}
]
}'const response = await fetch('https://rest-api.tbit.app/v1/templates/tpl_abc123/send', {
method: 'POST',
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
to: '573001234567',
components: [
{
type: 'body',
parameters: [
{
type: 'text',
text: 'John',
},
{
type: 'text',
text: 'your order #1234',
},
],
},
],
}),
});
const data = await response.json();import axios from 'axios';
const { data } = await axios.post(
'https://rest-api.tbit.app/v1/templates/tpl_abc123/send',
{
to: '573001234567',
components: [
{
type: 'body',
parameters: [
{
type: 'text',
text: 'John',
},
{
type: 'text',
text: 'your order #1234',
},
],
},
],
},
{
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
},
},
);import os
import requests
response = requests.post(
'https://rest-api.tbit.app/v1/templates/tpl_abc123/send',
headers={'X-API-Key': os.environ['TBIT_API_KEY']},
json={
'to': '573001234567',
'components': [
{
'type': 'body',
'parameters': [
{
'type': 'text',
'text': 'John',
},
{
'type': 'text',
'text': 'your order #1234',
},
],
},
],
},
)
data = response.json()<?php
$ch = curl_init('https://rest-api.tbit.app/v1/templates/tpl_abc123/send');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . getenv('TBIT_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '573001234567',
'components' => [
[
'type' => 'body',
'parameters' => [
[
'type' => 'text',
'text' => 'John',
],
[
'type' => 'text',
'text' => 'your order #1234',
],
],
],
],
]),
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);La risposta dell'invio significa solo che Meta HA ACCETTATO il messaggio; consegnato / letto / non riuscito arrivano qualche minuto dopo tramite i webhook di Meta. Per leggerli, passa `campaign` {key, name} nel body dell'invio (l'invio resta registrato sotto quella chiave, visibile anche in Piattaforma → Campagne) e interroga questo endpoint. `status` è sent, delivered, read o failed; `message_id` è il wamid che restituisce l'invio (arriva anche nella risposta dell'invio).
/v1/campaigns/my-app/executionscurl "https://rest-api.tbit.app/v1/campaigns/my-app/executions?since=2026-08-27T00:00:00Z&limit=100" \
-H "X-API-Key: $TBIT_API_KEY"const response = await fetch('https://rest-api.tbit.app/v1/campaigns/my-app/executions?since=2026-08-27T00:00:00Z&limit=100', {
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
},
});
const data = await response.json();import axios from 'axios';
const { data } = await axios.get(
'https://rest-api.tbit.app/v1/campaigns/my-app/executions?since=2026-08-27T00:00:00Z&limit=100',
{
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
},
},
);import os
import requests
response = requests.get(
'https://rest-api.tbit.app/v1/campaigns/my-app/executions?since=2026-08-27T00:00:00Z&limit=100',
headers={'X-API-Key': os.environ['TBIT_API_KEY']},
)
data = response.json()<?php
$ch = curl_init('https://rest-api.tbit.app/v1/campaigns/my-app/executions?since=2026-08-27T00:00:00Z&limit=100');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . getenv('TBIT_API_KEY'),
],
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);{
"data": [
{
"id": "6a90ea1f...",
"to": "573001234567",
"template_id": "tpl_abc123",
"message_id": "wamid.HBgLNTcz...",
"status": "failed",
"error_message": "This message was not delivered to maintain healthy ecosystem engagement.",
"sent_at": "2026-08-28T02:17:59.494Z",
"delivered_at": null,
"read_at": null
}
]
}Un oggetto modello:
{
"data": [
{
"id": "tpl_abc123",
"name": "order_confirmation",
"language": "es",
"status": "APPROVED",
"category": "UTILITY",
"channel_id": "6a7268abec6ecaf999a6c0ba",
"components": [
{
"type": "BODY",
"text": "Hola {{1}}, {{2}} ha sido confirmado."
}
],
"created_at": "2024-08-15T10:00:00Z"
}
]
}Un invio riuscito restituisce l'ID del messaggio:
{
"data": {
"message_sent": true,
"message_id": "wamid.HBgLNTczMDAxMjM0NTY3FQIAERgSMUY2RUZGM0Y3RTJCRTQ5AA==",
"parsed_message": "Hola John, your order #1234 ha sido confirmado."
}
}