Introduzione
L'API REST di WhatSMS consente di inviare messaggi, gestire contatti, ticket e campagne e di ascoltare eventi in tempo reale tramite webhook. Ogni richiesta è autenticata tramite API Key e isolata per tenant.
URL di base
https://api.whatsms.pt/api/v2
CRUD completo, paginazione strutturata, supporto media e rate limiting per API Key.
API Key per tenant
Ogni account ha la propria API Key. Crea e revoca in Impostazioni → Integrazioni → API Keys.
HTTPS obbligatorio
Tutte le richieste devono usare HTTPS. Le richieste HTTP vengono rifiutate automaticamente.
GDPR nativo
I dati restano su server europei. Conformità GDPR nativa, senza inviare dati al di fuori dell'UE.
Autenticazione
Ogni richiesta richiede l'header Authorization con l'API Key in formato Bearer. Ottieni la tua API Key in Impostazioni → Integrazioni → API Keys.
Header obbligatorio
Authorization: Bearer sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Esempio cURL
curl -X GET https://api.whatsms.pt/api/v2/contacts \ -H "Authorization: Bearer sk_live_xxxxxxxxxxxx" \ -H "Content-Type: application/json"
⚠️ Sicurezza
Non esporre mai l'API Key in codice lato client o repository pubblici. Usa variabili d'ambiente sul server. Se una key viene compromessa, revocala immediatamente in Impostazioni → Integrazioni → API Keys.
Errori
L'API usa codici HTTP standard. Il corpo dell'errore segue sempre questa struttura:
Formato dell'errore
{ "error": "Mensagem descritiva do erro" }| Codice | Significato |
|---|---|
| 200 | Successo |
| 201 | Creato con successo |
| 400 | Richiesta non valida — parametri mancanti o errati |
| 401 | Non autenticato — API Key non valida o mancante |
| 403 | Nessun permesso per questa risorsa |
| 404 | Risorsa non trovata |
| 429 | Limite di frequenza raggiunto — attendi prima di riprovare |
| 500 | Errore interno del server |
Ticket
Un ticket rappresenta una conversazione con un contatto. Raggruppa messaggi, canale, stato e l'agente responsabile.
/api/v2/ticketsElenca ticketParametri
Filtra per stato: open, pending, closed
Filtra per contatto
Pagina (default: 1)
Risultati per pagina (default: 20, max: 100)
Risposta
{
"tickets": [
{
"id": "uuid",
"status": "open",
"channel": "whatsapp",
"contact": { "id": "uuid", "name": "João Silva", "number": "351910000000" },
"lastMessage": "Olá, preciso de ajuda",
"createdAt": "2026-01-15T10:30:00Z"
}
],
"count": 42,
"hasMore": true
}/api/v2/tickets/:ticketIdOttieni ticket per IDParametri
ID del ticket
Risposta
{
"ticket": {
"id": "uuid",
"status": "open",
"channel": "whatsapp",
"contact": { "id": "uuid", "name": "João Silva", "number": "351910000000" },
"user": { "id": "uuid", "name": "Agente" },
"queue": { "id": "uuid", "name": "Suporte" },
"createdAt": "2026-01-15T10:30:00Z",
"updatedAt": "2026-01-15T11:00:00Z"
}
}/api/v2/ticketsCrea ticketCorpo della richiesta
{
"contactId": "uuid", // obrigatório
"status": "open", // open | pending | closed
"channel": "whatsapp", // whatsapp | sms | telegram
"whatsappId": "uuid", // canal WhatsApp a usar
"queueId": "uuid", // fila/departamento
"userId": "uuid" // agente responsável
}Risposta
{
"ticket": {
"id": "uuid",
"status": "open",
"channel": "whatsapp",
"createdAt": "2026-01-15T10:30:00Z"
}
}/api/v2/tickets/:ticketIdAggiorna ticketParametri
ID del ticket
Corpo della richiesta
{
"status": "closed", // open | pending | closed
"userId": "uuid", // reatribuir agente
"queueId": "uuid" // mover para fila
}Risposta
{
"ticket": { "id": "uuid", "status": "closed", "updatedAt": "2026-01-15T12:00:00Z" }
}Messaggi di un ticket
I messaggi sono annidati sotto il ticket. Per inviare un messaggio, usa POST /tickets/:id/messages.
/api/v2/tickets/:ticketId/messagesElenca i messaggi del ticketParametri
ID del ticket
Pagina (default: 1)
Risultati per pagina (default: 20)
Risposta
{
"messages": [
{
"id": "uuid",
"body": "Olá, preciso de ajuda",
"fromMe": false,
"mediaType": null,
"mediaUrl": null,
"ack": 3,
"createdAt": "2026-01-15T10:30:00Z"
}
],
"count": 15,
"hasMore": false
}/api/v2/tickets/:ticketId/messages60 req/min por API KeyInvia messaggioParametri
ID del ticket
Corpo della richiesta
{
"body": "Olá! Como posso ajudar?", // obrigatório (texto ou caption)
"mediaUrl": "https://...", // URL de imagem/documento/áudio
"mediaType": "image", // image | document | audio | video
"quotedMsgId": "uuid" // responder a mensagem específica
}Risposta
{
"message": {
"id": "uuid",
"body": "Olá! Como posso ajudar?",
"fromMe": true,
"ack": 1,
"createdAt": "2026-01-15T10:31:00Z"
}
}Contatti
Gestione completa dei contatti. Un contatto può avere più ticket su più canali.
/api/v2/contactsElenca contattiParametri
Cerca per nome, numero o email
Pagina (default: 1)
Risultati per pagina (default: 20)
Risposta
{
"contacts": [
{
"id": "uuid",
"name": "João Silva",
"number": "351910000000",
"email": "joao@exemplo.pt",
"profilePicUrl": "https://...",
"isGroup": false,
"createdAt": "2026-01-10T09:00:00Z"
}
],
"count": 150,
"hasMore": true
}/api/v2/contacts/:contactIdOttieni contatto per IDParametri
ID del contatto
Risposta
{
"contact": {
"id": "uuid",
"name": "João Silva",
"number": "351910000000",
"email": "joao@exemplo.pt",
"extraInfo": [{ "name": "NIF", "value": "123456789" }],
"createdAt": "2026-01-10T09:00:00Z"
}
}/api/v2/contactsCrea contattoCorpo della richiesta
{
"name": "João Silva", // obrigatório
"number": "351910000000", // obrigatório
"email": "joao@exemplo.pt",
"profilePicUrl": "https://...",
"extraInfo": [
{ "name": "NIF", "value": "123456789" }
]
}Risposta
{
"contact": {
"id": "uuid",
"name": "João Silva",
"number": "351910000000",
"createdAt": "2026-01-15T10:00:00Z"
}
}/api/v2/contacts/:contactIdAggiorna contattoParametri
ID del contatto
Corpo della richiesta
{
"name": "João M. Silva",
"email": "joao.novo@exemplo.pt",
"extraInfo": [{ "name": "Empresa", "value": "Acme Lda" }]
}Risposta
{
"contact": { "id": "uuid", "name": "João M. Silva", "updatedAt": "2026-01-15T11:00:00Z" }
}Campagne
Invio in massa a gruppi di contatti via WhatsApp o SMS, con pianificazione e controllo dello stato.
/api/v2/campaignsElenca campagneParametri
in attesa | in esecuzione | terminato | annullato
Pagina (default: 1)
Risposta
{
"campaigns": [
{
"id": "uuid",
"name": "Promoção Verão 2026",
"status": "finished",
"scheduledAt": "2026-06-01T09:00:00Z",
"sentCount": 342,
"failedCount": 3,
"createdAt": "2026-05-20T10:00:00Z"
}
],
"count": 8,
"hasMore": false
}/api/v2/campaignsCrea campagnaCorpo della richiesta
{
"name": "Promoção Verão 2026", // obrigatório
"message": "Olá {{name}}! ...", // obrigatório (suporta {{name}}, {{number}})
"whatsappId": "uuid", // canal a usar
"contactGroupId": "uuid", // grupo de contactos alvo
"scheduledAt": "2026-06-01T09:00:00Z" // null = envio imediato
}Risposta
{
"campaign": {
"id": "uuid",
"name": "Promoção Verão 2026",
"status": "pending",
"createdAt": "2026-05-20T10:00:00Z"
}
}Agenti IA
Gli agenti IA rispondono automaticamente ai ticket usando LLM (Cortecs Sovereign Cloud — conformità EU AI Act). Possono usare strumenti come KiviCare, calendario, CRM e knowledge base.
/api/v2/ai-agentsElenca agenti IANessun parametro obbligatorio.
Risposta
{
"agents": [
{
"id": "uuid",
"name": "Maria — Assistente FamilyClinic",
"model": "cortecs:llama-4-maverick",
"isActive": true,
"enabledIntegrations": ["kivicare"],
"handoffEnabled": true,
"createdAt": "2026-03-01T10:00:00Z"
}
]
}/api/v2/ai-agents/assignAssegna agente IA a un ticketCorpo della richiesta
{
"ticketId": "uuid", // obrigatório
"agentId": "uuid" // obrigatório — null para remover agente
}Risposta
{
"ticket": { "id": "uuid", "aiAgentId": "uuid", "updatedAt": "2026-01-15T10:00:00Z" }
}Webhooks
Configura un endpoint HTTPS per ricevere eventi in tempo reale. WhatSMS effettua un POST con un payload JSON firmato con HMAC-SHA256.
Header di firma
X-WhatSMS-Signature: sha256=<hmac_hex>
Verifica la firma con il tuo webhook secret per garantire che la richiesta provenga da WhatSMS.
Eventi disponibili
| Evento | Descrizione |
|---|---|
| message.received | Nuovo messaggio ricevuto da un contatto |
| message.sent | Messaggio inviato con successo |
| message.ack | Conferma di consegna/lettura (ack 1–5) |
| ticket.created | Nuovo ticket creato |
| ticket.updated | Ticket aggiornato (stato, agente, coda) |
| ticket.closed | Ticket chiuso |
| contact.created | Nuovo contatto creato |
| contact.updated | Contatto aggiornato |
| campaign.finished | Campagna terminata |
Payload di esempio — message.received
{
"event": "message.received",
"tenantId": "uuid",
"timestamp": "2026-01-15T10:30:00Z",
"data": {
"message": {
"id": "uuid",
"body": "Olá, preciso de ajuda",
"fromMe": false,
"mediaType": null,
"createdAt": "2026-01-15T10:30:00Z"
},
"ticket": { "id": "uuid", "status": "open" },
"contact": { "id": "uuid", "name": "João Silva", "number": "351910000000" }
}
}Limiti di velocità
I limiti sono per API Key e per finestra di 1 minuto. Quando raggiungi il limite ricevi un 429 con l'header Retry-After in secondi.
| Punto finale | Limite |
|---|---|
| Tutti gli endpoint v2 | 300 req/min por API Key |
| POST /tickets/:id/messages | 60 req/min por API Key |
| POST /campaigns | 10 req/min por API Key |
SDK e Integrazioni
Integra WhatSMS nel tuo stack con il node n8n ufficiale o direttamente via HTTP in qualsiasi linguaggio.
Nodo n8n
Node nativo per n8n con trigger di webhook e azioni di invio messaggi. Disponibile nel marketplace di n8n.
Presto disponibileHTTP / REST
API REST standard compatibile con qualsiasi linguaggio — JavaScript, Python, PHP, Go, ecc. Usa lo Swagger interattivo per esplorare e testare tutti gli endpoint.
Apri Swagger →Esempio — inviare un messaggio con fetch
const res = await fetch("https://api.whatsms.pt/api/v2/tickets/{ticketId}/messages", {
method: "POST",
headers: {
"Authorization": "Bearer sk_live_xxxxxxxxxxxx",
"Content-Type": "application/json"
},
body: JSON.stringify({ body: "Olá! Como posso ajudar?" })
});
const { message } = await res.json();
console.log(message.id);Documentazione completa e testa tutti gli endpoint nello Swagger interattivo.
⚡ Apri Swagger