History API
This API provides endpoints to add new questions and retrieve existing questions for authenticated users. All requests require a valid JWT token provided in the Authorization
header.
Base URL
The base URL for all endpoints is:
https://ailegis.pro/api/questions
Endpoints
POST /addQuestion
This endpoint allows you to add a new question along with a draft answer.
Request Headers
- Content-Type: application/json
- Authorization: Bearer
<token>
Request Body Parameters
Parameter | Type | Required | Description |
---|---|---|---|
questionText | string | Yes | The text of the question. |
draftText | string | Yes | The draft answer to the question. |
draftType | string | Yes | The type of the draft (e.g., "legalAdvice"). |
documents | {name:string,content:string}[] | Yes | List of document names related to the question. |
legalArea | string | Yes | The legal area relevant to the question. |
confidence | number | Yes | Confidence score (from 0 to 100) for the draft answer. |
Example Request
{
"questionText": "What are the legal implications of breaking a lease early?",
"draftText": "Breaking a lease early can result in...",
"draftType": "legalAdvice",
"documents": [{name:"lease_agreement.pdf" , content: "This doc..."}],
"legalArea": "Real Estate Law",
"confidence": 85
}
Example Use
const response = await fetch('https://ailegis.pro/api/questions/addQuestion', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer <token>`,
},
body: JSON.stringify({
questionText: 'What are the legal implications of breaking a lease early?',
draftText: 'Breaking a lease early can result in...',
draftType: 'legalAdvice',
documents: [{name:"lease_agreement.pdf" , content: "This doc..."}],
legalArea: 'Real Estate Law',
confidence: 85,
}),
});
const data = await response.json();
console.log(data);
Responses Codes
All endpoints adhere to standard HTTP status codes to indicate the success or failure of an API request.
200 OK
- The request was successful, question sucessfully stored.400 Bad Request
- One or more required fields are missing in the request body.401 Unauthorized
- The provided JWT token is missing, invalid, or expired.405 Method Not Allowed
- The HTTP method used is not supported for the requested endpoint.500 Internal Server Error
- An unexpected error occurred on the server.
GET /getQuestions
This endpoint retrieves all questions associated with the authenticated user.
Request Headers
- Authorization: Bearer
<token>
const response = await fetch('https://ailegis.pro/api/questions/getQuestions', {
method: 'GET',
headers: {
Authorization: `Bearer <token>`,
},
});
const data = await response.json();
console.log(data);
Responses
{
"data": [
{
"id": "question123",
"questionText": "What are the legal implications of breaking a lease early?",
"drafts": [
{
"draftType": "legalAdvice",
"draftText": "Breaking a lease early can result in...",
"documents": ["lease_agreement.pdf"],
"legalArea": "Real Estate Law",
"confidence": 85
}
]
}
// Additional questions...
]
}
Responses Codes
All endpoints adhere to standard HTTP status codes to indicate the success or failure of an API request.
200 OK
- The request was successful, question sucessfully stored.400 Bad Request
- One or more required fields are missing in the request body.401 Unauthorized
- The provided JWT token is missing, invalid, or expired.405 Method Not Allowed
- The HTTP method used is not supported for the requested endpoint.500 Internal Server Error
- An unexpected error occurred on the server.