botbook/src/10-rest/reports-api.md

183 lines
5 KiB
Markdown
Raw Normal View History

2025-12-03 19:56:35 -03:00
# Reports API
2025-12-21 23:40:39 -03:00
The Reports API provides endpoints for generating, managing, and exporting various types of reports from bot data and analytics.
2025-12-03 19:56:35 -03:00
2025-12-21 23:40:39 -03:00
## Status: Roadmap
2025-12-03 19:56:35 -03:00
2025-12-21 23:40:39 -03:00
This API is on the development roadmap. The endpoints documented below represent the planned interface design.
2025-12-03 19:56:35 -03:00
2025-12-21 23:40:39 -03:00
## Base URL
2025-12-03 19:56:35 -03:00
```
http://localhost:8080/api/v1/reports
```
## Authentication
2025-12-21 23:40:39 -03:00
Uses the standard botserver authentication mechanism with appropriate role-based permissions.
## Endpoints
### Report Generation
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/api/v1/reports/generate` | Generate a new report |
| GET | `/api/v1/reports/{report_id}/status` | Get report generation status |
| GET | `/api/v1/reports/{report_id}` | Get report metadata |
### Report Management
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/api/v1/reports` | List all reports |
| GET | `/api/v1/reports/{report_id}/download` | Download report file |
| DELETE | `/api/v1/reports/{report_id}` | Delete a report |
### Report Scheduling
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/api/v1/reports/schedule` | Create scheduled report |
| GET | `/api/v1/reports/schedule` | List scheduled reports |
| PUT | `/api/v1/reports/schedule/{schedule_id}` | Update schedule |
| DELETE | `/api/v1/reports/schedule/{schedule_id}` | Delete schedule |
### Report Templates
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/api/v1/reports/templates` | List available templates |
| POST | `/api/v1/reports/templates` | Create custom template |
| GET | `/api/v1/reports/templates/{template_id}` | Get template details |
## Report Types
| Type | Description |
|------|-------------|
| `usage` | Bot usage and activity metrics |
| `conversations` | Conversation analysis and statistics |
| `performance` | System performance metrics |
| `compliance` | Compliance and audit reports |
| `custom` | Custom report with user-defined metrics |
## Export Formats
2025-12-03 19:56:35 -03:00
2025-12-21 23:40:39 -03:00
| Format | Extension | Description |
|--------|-----------|-------------|
| PDF | `.pdf` | Formatted document with charts |
| CSV | `.csv` | Raw data export |
| Excel | `.xlsx` | Spreadsheet with multiple sheets |
| JSON | `.json` | Machine-readable format |
| HTML | `.html` | Web-viewable format |
2025-12-03 19:56:35 -03:00
2025-12-21 23:40:39 -03:00
## Request Examples
2025-12-03 19:56:35 -03:00
2025-12-21 23:40:39 -03:00
### Generate Usage Report
2025-12-03 19:56:35 -03:00
2025-12-21 23:40:39 -03:00
```bas
report_config = NEW OBJECT
report_config.type = "usage"
report_config.start_date = "2025-01-01"
report_config.end_date = "2025-01-31"
report_config.format = "pdf"
report_config.include_charts = true
2025-12-03 19:56:35 -03:00
2025-12-21 23:40:39 -03:00
result = POST "/api/v1/reports/generate", report_config
TALK "Report ID: " + result.report_id
```
### Check Report Status
2025-12-03 19:56:35 -03:00
2025-12-21 23:40:39 -03:00
```bas
status = GET "/api/v1/reports/rpt-123/status"
IF status.state = "completed" THEN
TALK "Report ready for download"
url = GET "/api/v1/reports/rpt-123/download"
ELSE
TALK "Report generation: " + status.progress + "%"
END IF
```
2025-12-03 19:56:35 -03:00
2025-12-21 23:40:39 -03:00
### Schedule Weekly Report
```bas
schedule = NEW OBJECT
schedule.type = "conversations"
schedule.format = "pdf"
schedule.cron = "0 8 * * 1"
schedule.recipients = ["manager@company.com"]
schedule.timezone = "America/New_York"
result = POST "/api/v1/reports/schedule", schedule
TALK "Scheduled report: " + result.schedule_id
```
2025-12-03 19:56:35 -03:00
2025-12-21 23:40:39 -03:00
### List Available Templates
```bas
templates = GET "/api/v1/reports/templates"
FOR EACH template IN templates
TALK template.name + " - " + template.description
NEXT
```
### Generate Custom Report
```bas
report = NEW OBJECT
report.type = "custom"
report.title = "Monthly Executive Summary"
report.sections = NEW ARRAY
report.sections.ADD({"type": "usage_summary"})
report.sections.ADD({"type": "top_conversations"})
report.sections.ADD({"type": "satisfaction_scores"})
report.format = "pdf"
result = POST "/api/v1/reports/generate", report
```
2025-12-03 19:56:35 -03:00
2025-12-21 23:40:39 -03:00
## Response Codes
| Code | Description |
|------|-------------|
| 200 | Success |
| 201 | Report created |
| 202 | Report generation started |
| 400 | Bad Request (invalid parameters) |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Report not found |
| 500 | Internal Server Error |
## Query Parameters
### Filtering
| Parameter | Type | Description |
|-----------|------|-------------|
| `type` | String | Filter by report type |
| `status` | String | Filter by status (pending, completed, failed) |
| `created_after` | DateTime | Reports created after date |
| `created_before` | DateTime | Reports created before date |
### Pagination
| Parameter | Type | Description |
|-----------|------|-------------|
| `limit` | Integer | Number of results (default: 20, max: 100) |
| `offset` | Integer | Pagination offset |
| `sort` | String | Sort field (created_at, name, type) |
| `order` | String | Sort order (asc, desc) |
## Required Permissions
| Operation | Required Role |
|-----------|---------------|
| Generate report | `report_creator` or `admin` |
| View reports | `report_viewer` or higher |
| Download reports | `report_viewer` or higher |
| Delete reports | `report_admin` or `admin` |
| Manage schedules | `report_admin` or `admin` |
| Manage templates | `report_admin` or `admin` |