Vai al contenuto
Menu

Cerca nel sito

Scrivi per cercare tra guide, blog, API e prodotto.

↑ ↓ per spostarti · Invio per aprire · Esc per chiudere

Riferimento dell'API

API

Modelli

Elenca e invia modelli di messaggio di WhatsApp approvati

Vedi come Markdown

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.

MetodoPercorsoDescrizione
GET/v1/templatesElenca i modelli di WhatsApp approvati
GET/v1/templates/:idDettaglio di un modello
POST/v1/templates/:id/sendInvia un modello a un contatto
GET/v1/channels/:channel_id/templatesModelli approvati di una linea WhatsApp
GET/v1/campaigns/:key/executionsStato di consegna per destinatario (invii fatti con una chiave di campagna)

Elencare i modelli

GET/v1/templates
curl "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);
GET/v1/templates/tpl_abc123
curl "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.

GET/v1/channels/6a7268abec6ecaf999a6c0ba/templates
curl "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);

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
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"
          }
        ]
      }
    ]
  }'
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);

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
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"
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);
Risposta
{
  "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:

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"
    }
  ]
}

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."
  }
}