Complete Health Tracking System with Option-Based Scoring
Base URL: http://localhost:8000/api
This is a major version update with breaking changes. Please read the migration guide before upgrading.
options array with predefined choices and pointsoption_id instead of answer_contentMajor architectural improvements for better performance and simplicity
# Register
curl -X POST http://localhost:8000/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"username": "john_doe",
"password": "secure_password",
"email_address": "john@example.com"
}'
# Login
curl -X POST http://localhost:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "john_doe",
"password": "secure_password"
}'
curl -X GET http://localhost:8000/api/questions \
-H "Authorization: Bearer YOUR_TOKEN"
{
"success": true,
"data": {
"questions": [
{
"question_id": 1,
"question_text": "How did you sleep?",
"category_name": "Physical Health",
"options": [
{"option_id": 1, "option_text": "Very well", "points": 5},
{"option_id": 2, "option_text": "Well", "points": 4},
{"option_id": 3, "option_text": "Fair", "points": 3},
{"option_id": 4, "option_text": "Poorly", "points": 2},
{"option_id": 5, "option_text": "Very poorly", "points": 1}
]
}
]
}
}
curl -X POST http://localhost:8000/api/answers \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"question_id": 1,
"option_id": 2
}'
curl -X GET "http://localhost:8000/api/health-score?period=week" \
-H "Authorization: Bearer YOUR_TOKEN"
Register a new user account
{
"username": "john_doe",
"password": "secure_password",
"email_address": "john@example.com"
}
Login and receive authentication token
{
"username": "john_doe",
"password": "secure_password"
}
Response:
{
"success": true,
"data": {
"token": "eyJ0eXAiOiJKV1QiLCJhbGci...",
"user": {
"user_id": 1,
"username": "john_doe",
"role": "user"
}
}
}
Logout and invalidate token
Validate current authentication token
Questions now always include their answer options with predefined points
display_order field and includes an options array. The question_type field has been removed.
Get all questions with their answer options
Query Parameters:
category_id (optional) - Filter by categorysearch (optional) - Search in question textlimit (optional) - Default: 50offset (optional) - Default: 0Response:
{
"success": true,
"data": {
"questions": [
{
"question_id": 1,
"category_id": 1,
"category_name": "Mental Health",
"question_text": "How would you rate your stress level?",
"display_order": 1,
"options": [
{"option_id": 1, "option_text": "No stress", "points": 5},
{"option_id": 2, "option_text": "Mild stress", "points": 4},
{"option_id": 3, "option_text": "Moderate stress", "points": 3},
{"option_id": 4, "option_text": "High stress", "points": 2},
{"option_id": 5, "option_text": "Severe stress", "points": 1}
]
}
],
"total": 20
}
}
Get a single question with options
Get all questions for a specific category
Create a new question
{
"category_id": 1,
"question_text": "Did you exercise today?",
"display_order": 5
}
Note: After creating a question, you must create options for it via database.
Update question (full replacement)
Update question (partial)
Delete question and all associated data
option_id instead of providing text. Points are automatically determined by the selected option.
Submit an answer by selecting an option
{
"question_id": 1,
"option_id": 3
}
Response:
{
"success": true,
"data": {
"answer": {
"answer_id": 123,
"user_id": 1,
"question_id": 1,
"option_id": 3,
"answer_date": "2026-01-29",
"question_text": "How would you rate your stress level?",
"option_text": "Moderate stress",
"points": 3
},
"action": "created"
}
}
💡 If you answer the same question twice on the same day, it updates the previous answer (action: "updated")
Get completion progress and health scores
Response:
{
"success": true,
"data": {
"overall": {
"total_questions": 20,
"answered_questions": 15,
"answered_today": 15,
"completion_percentage": 75.00,
"health_percentage": 58.50
},
"by_category": [
{
"category_id": 1,
"category_name": "Mental Health",
"total_questions": 5,
"answered_today": 5,
"completion_percentage": 100.00,
"health_percentage": 18.00
}
]
}
}
Get all answers submitted today
Query Parameters:
category_id (optional) - Filter by categoryGet historical answer data for charts
Query Parameters:
period (required) - week, month, or yearcategory_id (optional) - Filter by categoryAll scores are computed live from answers - no caching or stored reports
Get overall health score for a time period
Query Parameters:
period (optional) - week or month (default: week)Response:
{
"success": true,
"data": {
"period": "week",
"health_score": 425.50,
"total_answers": 140,
"days_answered": 7
}
}
Get health scores broken down by category
Query Parameters:
period (optional) - week or month (default: week)Get trend data for charts and graphs
Query Parameters:
period (optional) - week, month, or 6months (default: week)Response:
{
"success": true,
"data": {
"period": "week",
"trend": [
{"period": "2026-01-23", "score": 58.50, "answers_count": 20},
{"period": "2026-01-24", "score": 61.00, "answers_count": 20},
{"period": "2026-01-25", "score": 59.50, "answers_count": 19}
]
}
}
List all users
Get user details
Create new user
Update user (full)
Update user (partial)
Change user password
Delete user
Create API key for user
List user's API keys
Revoke API key
Get all categories
Get category details
Create category
Update category (full)
Update category (partial)
Delete category
Get system statistics
Get user statistics
Get data statistics
Export user data (CSV or JSON)
Generate system reports (weekly or monthly)
Send notification to user
Reset all user data
// OLD (v2.x)
questions.forEach(q => {
renderQuestion(q.question_content, q.question_type);
});
// NEW (v3.0)
questions.forEach(q => {
renderQuestion(q.question_text, q.options);
// Display options as radio buttons or select dropdown
q.options.forEach(opt => {
console.log(opt.option_text, opt.points);
});
});
// OLD (v2.x)
const answer = {
question_id: 1,
answer_content: "Often"
};
// NEW (v3.0)
const answer = {
question_id: 1,
option_id: selectedOptionId // Get from user selection
};
fetch('/api/answers', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify(answer)
});
// OLD (v2.x) - Fetch from stored reports
const report = await fetch('/api/users/1/weekly-reports/latest');
// NEW (v3.0) - Computed live
const score = await fetch('/api/health-score?period=week');
const byCategory = await fetch('/api/health-score/by-category?period=week');
const trend = await fetch('/api/health-score/trend?period=week');
// OLD (v2.x)
const weeklyData = await fetch('/api/users/1/weekly-reports');
// NEW (v3.0)
const trendData = await fetch('/api/health-score/trend?period=week');
// Use trendData.data.trend for chart
The following endpoints have been permanently removed:
Replace with live computed endpoints: /health-score, /health-score/by-category, /health-score/trend
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| Authentication | |||
| POST | /auth/register | No | Register new user |
| POST | /auth/login | No | Login and get token |
| POST | /auth/logout | Yes | Logout |
| GET | /auth/validate | Yes | Validate token |
| Questions | |||
| GET | /questions | Yes | List questions with options |
| GET | /questions/{id} | Yes | Get question with options |
| POST | /questions | Admin | Create question |
| PUT | /questions/{id} | Admin | Update question |
| PATCH | /questions/{id} | Admin | Partial update |
| DELETE | /questions/{id} | Admin | Delete question |
| Answers | |||
| POST | /answers | Yes | Submit answer (option_id) |
| GET | /answers/progress | Yes | Get progress |
| GET | /answers/today | Yes | Today's answers |
| GET | /answers/history | Yes | Historical data |
| Health Score | |||
| GET | /health-score | Yes | Overall score |
| GET | /health-score/by-category | Yes | Scores by category |
| GET | /health-score/trend | Yes | Trend data |
| Users | |||
| GET | /users | Admin | List users |
| GET | /users/{id} | Yes | Get user |
| POST | /users | Admin | Create user |
| PUT | /users/{id} | Yes | Update user |
| PATCH | /users/{id} | Yes | Partial update |
| DELETE | /users/{id} | Admin | Delete user |
| Categories | |||
| GET | /categories | Yes | List categories |
| GET | /categories/{id} | Yes | Get category |
| POST | /categories | Admin | Create category |
| Admin | |||
| GET | /admin/stats | Admin | System statistics |
| GET | /admin/users/statistics | Admin | User statistics |
| GET | /admin/data/statistics | Admin | Data statistics |
| GET | /admin/export/users | Admin | Export users |
| GET | /admin/reports/{type} | Admin | Generate report |
For complete details, see: Full API Documentation | Migration Guide | What's New
Gezondheids Meter API v3.0 - Built with ❤️