This document provides comprehensive documentation for the Audiobook Automation System REST API.
http://localhost:8000
Replace with your actual server URL and port
The API provides endpoints for:
- Request Management - Creating and managing audiobook requests
- Status Checking - Monitoring request status
- Approval/Rejection - Token-based approval workflow
- System Information - Health checks and system status
The API uses token-based authentication for approval/rejection actions. Most read operations are public, while write operations require valid tokens.
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Tokens are:
- URL-safe - Can be included in URLs
- Time-limited - Expire after configured duration
- Single-use - Become invalid after use
Returns the main homepage.
Response:
- Content-Type:
text/html - Status:
200 OK
Submit a new audiobook request.
Request Body:
{
"title": "The Hitchhiker's Guide to the Galaxy",
"author": "Douglas Adams",
"isbn": "9780345391803",
"description": "A science fiction comedy series",
"priority": "normal",
"format": "mp3",
"narrator": "Stephen Fry"
}Required Fields:
title(string) - Book titleauthor(string) - Author name
Optional Fields:
isbn(string) - ISBN numberdescription(string) - Book descriptionpriority(enum) -low,normal,highformat(enum) -mp3,m4a,flacnarrator(string) - Preferred narrator
Response:
{
"status": "success",
"message": "Request submitted successfully",
"request_id": 123,
"approval_token": "abc123...",
"rejection_token": "def456..."
}Status Codes:
200 OK- Request submitted successfully400 Bad Request- Invalid request data429 Too Many Requests- Rate limit exceeded500 Internal Server Error- Server error
List all audiobook requests (paginated).
Query Parameters:
page(integer, default: 1) - Page numberlimit(integer, default: 20, max: 100) - Items per pagestatus(enum) - Filter by status:pending,approved,rejectedsort(enum) - Sort order:newest,oldest,title,author
Response:
{
"requests": [
{
"id": 123,
"title": "The Hitchhiker's Guide to the Galaxy",
"author": "Douglas Adams",
"status": "pending",
"created_at": "2025-06-16T10:30:00Z",
"updated_at": "2025-06-16T10:30:00Z"
}
],
"pagination": {
"page": 1,
"limit": 20,
"total": 45,
"total_pages": 3
}
}Get details for a specific request.
Path Parameters:
request_id(integer) - Request ID
Response:
{
"id": 123,
"title": "The Hitchhiker's Guide to the Galaxy",
"author": "Douglas Adams",
"isbn": "9780345391803",
"description": "A science fiction comedy series",
"status": "pending",
"priority": "normal",
"format": "mp3",
"narrator": "Stephen Fry",
"created_at": "2025-06-16T10:30:00Z",
"updated_at": "2025-06-16T10:30:00Z",
"approved_at": null,
"rejected_at": null
}Status Codes:
200 OK- Request found404 Not Found- Request doesn't exist
Approve a request using a valid approval token.
Path Parameters:
token(string) - Approval token
Response:
- Content-Type:
text/html - Status:
200 OK- Success page - Status:
400 Bad Request- Invalid/expired token - Status:
404 Not Found- Token not found
Reject a request using a valid rejection token.
Path Parameters:
token(string) - Rejection token
Response:
- Content-Type:
text/html - Status:
200 OK- Rejection page - Status:
400 Bad Request- Invalid/expired token - Status:
404 Not Found- Token not found
Health check endpoint for monitoring.
Response:
{
"status": "healthy",
"timestamp": "2025-06-16T10:30:00Z",
"version": "1.0.0",
"database": "connected",
"notifications": "enabled"
}Status Codes:
200 OK- System healthy503 Service Unavailable- System issues
System statistics and metrics.
Response:
{
"requests": {
"total": 1247,
"pending": 23,
"approved": 1089,
"rejected": 135
},
"activity": {
"requests_today": 15,
"requests_this_week": 89,
"requests_this_month": 312
},
"system": {
"uptime_seconds": 3600,
"database_size_mb": 12.4,
"log_size_mb": 2.1
}
}All error responses follow a consistent format:
{
"error": {
"code": "VALIDATION_ERROR",
"message": "The title field is required",
"details": {
"field": "title",
"constraint": "required"
}
},
"timestamp": "2025-06-16T10:30:00Z",
"request_id": "req_abc123"
}| Code | Description |
|---|---|
VALIDATION_ERROR |
Invalid request data |
TOKEN_EXPIRED |
Approval/rejection token expired |
TOKEN_USED |
Token already used |
TOKEN_INVALID |
Token format invalid |
RATE_LIMIT_EXCEEDED |
Too many requests |
DATABASE_ERROR |
Database operation failed |
NOTIFICATION_ERROR |
Notification delivery failed |
INTERNAL_ERROR |
Unexpected server error |
curl -X POST http://localhost:8000/audiobook-requests \
-H "Content-Type: application/json" \
-d '{
"title": "Dune",
"author": "Frank Herbert",
"description": "Epic science fiction novel",
"priority": "high",
"format": "mp3"
}'curl "http://localhost:8000/requests?status=pending&limit=10"import httpx
# Submit a new request
response = httpx.post('http://localhost:8000/audiobook-requests', json={
'title': 'The Martian',
'author': 'Andy Weir',
'description': 'Survival story on Mars',
'priority': 'normal'
})
if response.status_code == 200:
data = response.json()
print(f"Request submitted with ID: {data['request_id']}")
else:
print(f"Error: {response.status_code} - {response.text}")// Submit a new request
fetch('/audiobook-requests', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
title: 'Ready Player One',
author: 'Ernest Cline',
description: 'Virtual reality adventure',
priority: 'normal'
})
})
.then(response => response.json())
.then(data => {
console.log('Request submitted:', data.request_id);
})
.catch(error => {
console.error('Error:', error);
});API endpoints are rate-limited to prevent abuse:
- Request submission: 10 requests per hour per IP
- Status queries: 100 requests per hour per IP
- General endpoints: 1000 requests per hour per IP
Rate limit headers are included in responses:
X-RateLimit-Limit: 10
X-RateLimit-Remaining: 7
X-RateLimit-Reset: 1640995200The system can send webhooks for various events. See Webhooks Documentation for details.
# Run API tests
python -m pytest tests/test_webui.py -v
# Run specific endpoint tests
python -m pytest tests/test_webui.py::test_submit_request -vThe system includes a built-in API test page at /api-test (when debug mode is enabled) for manual testing of endpoints.
- Configuration Reference - Complete configuration options
- Webhooks - Webhook configuration and payloads
- Database Schema - Database structure and queries
- Security - Security considerations
Need help? Check the troubleshooting guide or open an issue on GitHub!