Skip to main content

Create Chat Session

The AI Agent API enables you to create a new chat session by sending a POST request to the /chat/Chatbot/GetSession endpoint.

Request URL: https://usapi.hottask.com/chat/Chatbot/GetSession

Method: POST

The API request must include the following headers:

  • Authorization: <Your-Secret-Key> - The secret key for authenticating the API request
  • Content-Type: application/json - The content type of the request payload (must be application/json)

The request body should contain the following parameters:

{
// The unique identifier (ID) of the chatbot
"serialNumber": "3254a9d0424c4806b9ea3d0763ccfxxx"
}
  • serialNumber - The unique identifier (ID) of the chatbot

JavaScript (Fetch API)

const res = await fetch('https://usapi.hottask.com/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);

Python (Requests Library)

import requests
import json

url = 'https://usapi.hottask.com/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

curl 'https://usapi.hottask.com/chat/Chatbot/GetSession' \
-X POST \
-H 'Authorization: <Your-Secret-Key>' \
-H 'Content-Type: application/json' \
-d '{"serialNumber":"3254a9d0424c4806b9ea3d0763ccfxxx"}'

HTTP Request

POST /chat/Chatbot/GetSession HTTP/1.1
Host: usapi.hottask.com
Authorization: <Your-Secret-Key>
Content-Type: application/json

{
"serialNumber": "3254a9d0424c4806b9ea3d0763ccfxxx"
}

The API response will be a JSON object with the following structure:

{
"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": ""
}
If the request fails, you should: 1. Check the HTTP status code for network-level errors 2. Examine the `Code` and `Message` fields in the response for business-level errors 3. The `Message` field will contain detailed error information