An API for optimizing work goals using expected value theory and integrating with Fatebook for prediction tracking.
The API is now live at: https://dcm31--019899c30691716293d39932f5c6be80.web.val.run/api/
- Interactive API Docs: /api/docs
- OpenAPI Spec: /api/openapi.yaml
Most endpoints require your Fatebook API key. Get yours at: https://fatebook.io/api-setup
POST /api/calculate-optimal-goal
Calculate the optimal work goal based on probability assessments.
Example Request:
{ "settings": { "minValue": 1, "maxValue": 6, "increment": 0.5, "usePomodoros": false }, "probabilities": { "2": 0.9, "3": 0.7, "4": 0.5, "5": 0.3 } }
POST /api/quick-goal
One-shot endpoint that calculates optimal goal AND creates it in Fatebook.
Example Request:
{ "fatebookApiKey": "your-api-key", "probabilities": { "2": 0.9, "3": 0.7, "4": 0.5 }, "settings": { "usePomodoros": true } }
GET /api/fatebook-goals?apiKey=your-key&limit=50&resolved=false
POST /api/fatebook-goals
{ "fatebookApiKey": "your-key", "goalValue": 3, "unit": "hours", "confidence": 0.7 }
POST /api/fatebook-goals/{questionId}/resolve
{ "fatebookApiKey": "your-key", "resolution": "YES" }
POST /api/fatebook-goals/{questionId}/forecast
{ "fatebookApiKey": "your-key", "forecast": 0.8 }
GET /api/analyze-performance?fatebookApiKey=your-key&timeframe=month
Returns calibration metrics, success rates, trends, and recommendations.
# Calculate optimal goal curl -X POST https://dcm31--019899c30691716293d39932f5c6be80.web.val.run/api/calculate-optimal-goal \ -H "Content-Type: application/json" \ -d '{ "settings": {"minValue": 1, "maxValue": 4, "increment": 0.5, "usePomodoros": false}, "probabilities": {"1": 0.95, "1.5": 0.8, "2": 0.6, "2.5": 0.4} }' # Quick workflow - calculate and create goal curl -X POST https://dcm31--019899c30691716293d39932f5c6be80.web.val.run/api/quick-goal \ -H "Content-Type: application/json" \ -d '{ "fatebookApiKey": "your-api-key", "probabilities": {"2": 0.8, "3": 0.6, "4": 0.4} }'
// Calculate optimal goal
const response = await fetch('/api/calculate-optimal-goal', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
settings: { minValue: 1, maxValue: 6, increment: 0.5, usePomodoros: false },
probabilities: { "2": 0.9, "3": 0.7, "4": 0.5 }
})
});
const result = await response.json();
console.log('Optimal goal:', result.optimalGoal);
// Get performance analysis
const analysis = await fetch(`/api/analyze-performance?fatebookApiKey=${apiKey}&timeframe=month`);
const data = await analysis.json();
console.log('Success rate:', data.successRate + '%');
import requests # Calculate optimal goal response = requests.post( 'https://dcm31--019899c30691716293d39932f5c6be80.web.val.run/api/calculate-optimal-goal', json={ 'settings': {'minValue': 1, 'maxValue': 6, 'increment': 0.5, 'usePomodoros': False}, 'probabilities': {'2': 0.9, '3': 0.7, '4': 0.5} } ) result = response.json() print(f"Optimal goal: {result['optimalGoal']['value']} {result['optimalGoal']['unit']}") # Quick workflow quick_response = requests.post( 'https://dcm31--019899c30691716293d39932f5c6be80.web.val.run/api/quick-goal', json={ 'fatebookApiKey': 'your-api-key', 'probabilities': {'2': 0.8, '3': 0.6, '4': 0.4} } ) print(quick_response.json()['recommendation'])
Let's test this API right here! Try the quick goal workflow:
// Test the API with your actual Fatebook key
const testQuickGoal = async () => {
const response = await fetch('https://dcm31--019899c30691716293d39932f5c6be80.web.val.run/api/quick-goal', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
fatebookApiKey: 'hgyrqtq5ube7daowumtog6', // Your key from the documents
probabilities: {
"1": 0.95,
"2": 0.85,
"3": 0.7,
"4": 0.5
},
settings: {
usePomodoros: false
}
})
});
const result = await response.json();
console.log('API Test Result:', result);
return result;
};
// Run the test
testQuickGoal();
Now that you have a full API, you can:
- CLI Tool: Create a command-line tool that asks for probabilities and creates goals
- Slack Bot: Integrate with Slack for team goal setting
- Mobile App: Build a mobile app that uses the API
- Browser Extension: Chrome extension for quick goal setting
- Automation: Set up cron jobs to analyze performance and send reports
- Integration with other tools: Connect with Toggl, RescueTime, etc.
- ✅ Calculate optimal goals using expected value theory
- ✅ Full Fatebook integration (create, resolve, update forecasts)
- ✅ Performance analysis with calibration metrics
- ✅ RESTful API with comprehensive error handling
- ✅ OpenAPI specification with interactive docs
- ✅ Backward compatibility with existing frontend
- ✅ Rate limiting and input validation
- ✅ Detailed analytics and recommendations
All endpoints return consistent error responses:
{ "error": "Human-readable error message", "details": "Technical details for debugging", "code": "ERROR_CODE_FOR_PROGRAMMATIC_HANDLING" }
With this API in place, you can now:
- Use the
/api/quick-goalendpoint for automated goal setting - Build integrations with other productivity tools
- Create automated workflows for goal tracking and analysis
- Develop mobile or desktop applications
- Set up monitoring and alerting based on performance metrics
The API is fully functional and ready for production use!