Riferimento API completo per l'integrazione con la piattaforma Customer Support AI Agent. Include autenticazione, endpoint, schemi di richiesta/riposta e esempi di codice pratici.
L'API supporta due metodi di autenticazione:
Genera token JWT a breve termine per l'autenticazione del widget. Questo endpoint consente ai widget di ottenere token sicuri utilizzando solo il client_id, evitando la necessità di esporre il client_secret negli ambienti browser.
Se installi il widget con il tag script standard, non è necessario chiamarlo tu stesso: l'embed esegue lo scambio al caricamento. Chiamalo direttamente solo quando stai costruendo la tua superficie di chat contro l'API. L'Origin della richiesta deve essere nell'elenco delle origini consentite dell'applicazione e i mint sono limitati a 30 al minuto per IP.
curl -X POST https://app.companin.tech/api/v1/auth/widget-token \ -H "Content-Type: application/json" \ -H "Origin: https://your-site.example" \ -d '{ "client_id": "YOUR_CLIENT_ID" }'Risposta:
{ "token": "eyJ...", "expires_in": 3600, "token_type": "Bearer" }Le richieste API sono limitate a 100 all'ora per organizzazione. Superare il limite restituisce HTTP 429; le risposte che includono un suggerimento di backoff contengono un'intestazione Retry-After. Il traffico dei widget è misurato separatamente e non è conteggiato contro questo budget. Se hai bisogno di un limite più alto, contattaci.
Tutti gli errori API restituiscono risposte JSON strutturate con codici di stato, dettagli sugli errori e campi dati opzionali.
{ "status": "error", "status_code": 401, "detail": "Authentication required - ...", "data": null }Chiama questi endpoint dal tuo server. Il X-API-Secret non deve mai raggiungere il browser e le richieste del browser dal tuo stesso dominio vengono rifiutate da CORS — vedi Supporto CORS qui sotto.
Gestisci le personalità degli agenti AI con configurazioni personalizzate.
curl -X GET https://app.companin.tech/api/v1/agents/ \ -H "X-API-Key: YOUR_CLIENT_ID" \ -H "X-API-Secret: YOUR_CLIENT_SECRET"curl -X POST https://app.companin.tech/api/v1/agents/ \ -H "X-API-Key: YOUR_CLIENT_ID" \ -H "X-API-Secret: YOUR_CLIENT_SECRET" \ -H "Content-Type: application/json" \ -d '{ "name": "Customer Support Bot", "description": "Helpful agent for customer inquiries", "tone": "professional", "language": "en", "default_tasks": ["answer_questions", "provide_support"], "is_active": true }'Crea sessioni per visitatori anonimi per interazioni temporanee.
curl -X POST https://app.companin.tech/api/v1/sessions/ \ -H "X-API-Key: YOUR_CLIENT_ID" \ -H "X-API-Secret: YOUR_CLIENT_SECRET" \ -H "Content-Type: application/json" \ -d '{ "agent_id": "550e8400-e29b-41d4-a716-446655440000", "visitor_id": "visitor-123", "locale": "en", "metadata": { "source": "website", "page": "/contact" } }'curl -X POST https://app.companin.tech/api/v1/sessions/${SESSION_ID}/messages \ -H "X-API-Key: YOUR_CLIENT_ID" \ -H "X-API-Secret: YOUR_CLIENT_SECRET" \ -H "Content-Type: application/json" \ -d '{ "content": "Hello, I need help with my order", "metadata": { "user_type": "customer" } }'Crea conversazioni persistenti per utenti autenticati.
curl -X POST https://app.companin.tech/api/v1/conversations/ \ -H "X-API-Key: YOUR_CLIENT_ID" \ -H "X-API-Secret: YOUR_CLIENT_SECRET" \ -H "Content-Type: application/json" \ -d '{ "agent_id": "550e8400-e29b-41d4-a716-446655440000", "customer_id": "user-456", "title": "Order Support", "locale": "en" }'curl -X POST https://app.companin.tech/api/v1/conversations/${CONVERSATION_ID}/messages \ -H "X-API-Key: YOUR_CLIENT_ID" \ -H "X-API-Secret: YOUR_CLIENT_SECRET" \ -H "Content-Type: application/json" \ -d '{ "content": "Can you help me track my order?", "metadata": { "order_id": "12345" } }'Memorizza e gestisci il contesto utente per interazioni personalizzate.
curl -X POST https://app.companin.tech/api/v1/contexts \ -H "X-API-Key: YOUR_CLIENT_ID" \ -H "X-API-Secret: YOUR_CLIENT_SECRET" \ -H "Content-Type: application/json" \ -d '{ "user_reference": "user-456", "traits": { "name": "John Doe", "email": "john@example.com", "subscription_tier": "premium", "preferences": { "language": "en", "notifications": true } } }'Carica e gestisci fonti di conoscenza per i tuoi agenti.
Nota: POST /api/v1/knowledge/files/ registra un'entrata di file di conoscenza e i suoi metadati — non accetta il contenuto del file. Per caricare il file stesso, utilizza la dashboard, o POST dati di modulo multipart a /knowledge-base/ con una sessione di dashboard autenticata.
# Registers a knowledge file entry (metadata only — see the note above). curl -X POST https://app.companin.tech/api/v1/knowledge/files/ \ -H "X-API-Key: YOUR_CLIENT_ID" \ -H "X-API-Secret: YOUR_CLIENT_SECRET" \ -H "Content-Type: application/json" \ -d '{ "title": "Product Manual", "file_type": "pdf", "summary": "Installation and troubleshooting guide" }'curl -X POST https://app.companin.tech/api/v1/knowledge/qa/ \ -H "X-API-Key: YOUR_CLIENT_ID" \ -H "X-API-Secret: YOUR_CLIENT_SECRET" \ -H "Content-Type: application/json" \ -d '{ "question": "What are your business hours?", "answer": "We are open Monday to Friday, 9 AM to 6 PM EST.", "tags": ["hours", "support"] }'// 1. Ottieni token widget per chat basata su browser async function getWidgetToken() { const response = await fetch('https://app.companin.tech/api/v1/auth/widget-token', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ client_id: 'YOUR_CLIENT_ID' }) }); return (await response.json()).token; } // 2. Crea una sessione per visitatore anonimo async function startSupportSession(token, agentId) { const response = await fetch('https://app.companin.tech/api/v1/sessions/', { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ agent_id: agentId, visitor_id: 'visitor-' + Date.now(), metadata: { source: 'support_widget' } }) }); return await response.json(); } // 3. Invia messaggio del cliente e ottieni risposta AI async function sendMessage(token, sessionId, message) { const response = await fetch(`https://app.companin.tech/api/v1/sessions/${sessionId}/messages`, { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ content: message, metadata: { user_type: 'customer' } }) }); return await response.json(); } // Esempio di utilizzo const token = await getWidgetToken(); const session = await startSupportSession(token, 'agent-uuid'); const result = await sendMessage(token, session.data.id, 'Ho bisogno di aiuto con il mio ordine');// 1. Crea contesto utente per personalizzazione async function createUserContext(userId, userData) { const response = await fetch('https://app.companin.tech/api/v1/contexts', { method: 'POST', headers: { 'X-API-Key': 'YOUR_CLIENT_ID', 'X-API-Secret': 'YOUR_CLIENT_SECRET', 'Content-Type': 'application/json' }, body: JSON.stringify({ user_reference: userId, traits: { name: userData.name, purchase_history: userData.purchases, preferences: userData.preferences } }) }); return await response.json(); } // 2. Crea conversazione persistente con contesto async function startPersonalizedChat(agentId, userId) { const response = await fetch('https://app.companin.tech/api/v1/conversations/', { method: 'POST', headers: { 'X-API-Key': 'YOUR_CLIENT_ID', 'X-API-Secret': 'YOUR_CLIENT_SECRET', 'Content-Type': 'application/json' }, body: JSON.stringify({ agent_id: agentId, customer_id: userId, user_context_id: userId, title: 'Product Recommendations', metadata: { source: 'product_page' } }) }); return await response.json(); } // 3. Chatta con conoscenza del prodotto async function askAboutProduct(conversationId, question) { const response = await fetch(`https://app.companin.tech/api/v1/conversations/${conversationId}/messages`, { method: 'POST', headers: { 'X-API-Key': 'YOUR_CLIENT_ID', 'X-API-Secret': 'YOUR_CLIENT_SECRET', 'Content-Type': 'application/json' }, body: JSON.stringify({ content: question, metadata: { context: 'product_inquiry' } }) }); return await response.json(); } // Esempio di utilizzo await createUserContext('user-123', { name: 'Alice', purchases: ['laptop-1', 'mouse-2'], preferences: { category: 'electronics' } }); const conversation = await startPersonalizedChat('agent-uuid', 'user-123'); const result = await askAboutProduct(conversation.data.id, 'Quale laptop mi consigli?');// 1. Carica documentazione del prodotto async function registerDocumentation(title, summary) { // Registers the entry + its metadata. File content is uploaded separately // (dashboard, or multipart POST to /knowledge-base/ with a dashboard session). const response = await fetch('https://app.companin.tech/api/v1/knowledge/files/', { method: 'POST', headers: { 'X-API-Key': 'YOUR_CLIENT_ID', 'X-API-Secret': 'YOUR_CLIENT_SECRET', 'Content-Type': 'application/json' }, body: JSON.stringify({ title, file_type: 'pdf', summary }) }); return await response.json(); } // 2. Aggiungi voci FAQ async function addFAQ(question, answer, tags) { const response = await fetch('https://app.companin.tech/api/v1/knowledge/qa/', { method: 'POST', headers: { 'X-API-Key': 'YOUR_CLIENT_ID', 'X-API-Secret': 'YOUR_CLIENT_SECRET', 'Content-Type': 'application/json' }, body: JSON.stringify({ question, answer, tags, source: 'manual' }) }); return await response.json(); } // 3. Aggiungi contenuti web async function addWebContent(url, title) { const response = await fetch('https://app.companin.tech/api/v1/knowledge/urls/', { method: 'POST', headers: { 'X-API-Key': 'YOUR_CLIENT_ID', 'X-API-Secret': 'YOUR_CLIENT_SECRET', 'Content-Type': 'application/json' }, body: JSON.stringify({ url, title }) }); return await response.json(); } // Esempio di utilizzo const fileEntry = await registerDocumentation('User Manual v2.0', 'Setup and troubleshooting'); const faq = await addFAQ( 'Come posso reimpostare la mia password?', 'Vai su impostazioni e clicca su "Reimposta password"...', ['password', 'security'] ); const webContent = await addWebContent( 'https://example.tech/blog/new-features', 'Annuncio delle nuove funzionalità' );curl -X POST https://app.companin.tech/api/v1/auth/widget-token \ -H "Content-Type: application/json" \ -d '{"client_id":"YOUR_CLIENT_ID"}'fetch('https://app.companin.tech/api/v1/sessions', { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ agent_id: 'AGENT_UUID' }) })