Crea sessione chat
L'API di app.neoagent.co fornisce la funzionalità per creare una nuova sessione di chat inviando una richiesta POST all'endpoint /chat/Chatbot/GetSession.
Endpoint
URL della Richiesta: https://app.neoagent.co/chat/Chatbot/GetSession
Metodo: POST
Headers richiesti
La richiesta API deve includere i seguenti header:
Authorization: <Your-Secret-Key>- string, obbligatorio - La chiave segreta per autenticare la richiesta APIContent-Type: application/json- string, obbligatorio - Il tipo di contenuto del payload della richiesta (deve essere application/json)
Corpo della Richiesta
Il corpo della richiesta deve contenere i seguenti parametri:
{
// stringa, obbligatoria - Identificatore univoco (ID) del chatbot
"serialNumber": "3254a9d0424c4806b9ea3d0763xxxxxx",
}
Parametri
serialNumber- stringa, obbligatorio - Identificatore univoco (ID) del chatbot
Esempi di Richiesta
- JavaScript (Fetch API)
- Python (Requests)
- cURL
- HTTP Raw
const res = await fetch('https://app.neoagent.co/chat/Chatbot/GetSession', {
method: 'POST',
headers: {
"Authorization": "<Your-Secret-Key>",
"Content-Type": "application/json"
},
body: JSON.stringify({
"serialNumber": "3254a9d0424c4806b9ea3d0763ccfxxx"
})
});
const data = await res.json();
console.log(data);
import requests
import json
url = 'https://app.neoagent.co/chat/Chatbot/GetSession'
headers = {
"Authorization": "<Your-Secret-Key>",
"Content-Type": "application/json"
}
data = {
"serialNumber": "3254a9d0424c4806b9ea3d0763ccfxxx"
}
response = requests.post(url, headers=headers, json=data)
data = response.json()
print(data)
curl 'https://app.neoagent.co/chat/Chatbot/GetSession' \
-X POST \
-H 'Authorization: <Your-Secret-Key>' \
-H 'Content-Type: application/json' \
-d '{"serialNumber":"3254a9d0424c4806b9ea3d0763ccfxxx"}'
POST /chat/Chatbot/GetSession HTTP/1.1
Host: app.neoagent.co
Authorization: <Your-Secret-Key>
Content-Type: application/json
{
"serialNumber": "3254a9d0424c4806b9ea3d0763ccfxxx"
}
Risposta
La risposta API sarà un oggetto JSON con la seguente struttura:
{
"Data": {
"SessionID": 123456
},
// string - API version
"Version": "1.0.0",
// boolean - Operation success status
"Success": true,
// integer - HTTP status code
"Code": 200,
// string - Error message if any
"Message": ""
}
Gestione degli Errori
Se la richiesta fallisce, dovresti:
- Controllare il codice di stato HTTP per errori a livello di rete
- Esaminare i campi
CodeeMessagenella risposta per errori a livello business - Il campo
Messageconterrà informazioni dettagliate sull'errore