# Documentazione API

Cognitor Assistant espone un'API REST basata su FastAPI per l'integrazione con altri sistemi.

Endpoint

GET /health

Health check dell'applicazione.

Response:

json
{
  "status": "ok"
}

POST /auth/token

Autenticazione utente, restituisce JWT token.

Request Body (form-urlencoded):

  • username: Username dell'utente
  • password: Password dell'utente

Response:

json
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "bearer"
}

Esempio:

bash
curl -X POST http://localhost:8000/auth/token \
  -d "username=admin&password=admin123"

POST /chatbot/message

Invia un messaggio al chatbot (richiede autenticazione).

Headers:

  • Authorization: Bearer token JWT

Request Body:

json
{
  "message": "Ciao!",
  "session_id": "optional-session-id"
}

Response:

json
{
  "response": "Ciao! Come posso aiutarti?",
  "session_id": "uuid-della-sessione"
}

Esempio:

bash
curl -X POST http://localhost:8000/chatbot/message \
  -H "Authorization: Bearer " \
  -H "Content-Type: application/json" \
  -d '{"message": "Ciao!"}'

Autenticazione

L'API utilizza JWT (JSON Web Tokens) per l'autenticazione. Per accedere agli endpoint protetti:

  1. Ottenere un token tramite /auth/token
  2. Includere il token nell'header Authorization: Bearer

Errori

Gli endpoint possono restituire i seguenti codici di errore:

  • 401 Unauthorized: Token mancante o invalido
  • 404 Not Found: Risorsa non trovata
  • 500 Internal Server Error: Errore interno del server

CORS

L'API configura CORS per permettere richieste da qualsiasi origine (allow_origins=["*"]).