🔐 Authentication
All API requests require authentication using an API key in the header:
Authorization: Bearer YOUR_API_KEY
X-WIA-Client-ID: your_client_id
Obtaining API Keys
POST /auth/apikey
Content-Type: application/json
{
"client_id": "your_client_id",
"client_secret": "your_client_secret",
"scope": ["analytics.read", "analytics.write"]
}
📊 Analytics Endpoints
POST /analytics/descriptive
Perform descriptive analytics on a dataset
Request Body:
{
"dataset_id": "string",
"metrics": ["mean", "median", "std", "quartiles"],
"group_by": ["category"],
"filters": {
"date_range": {
"start": "2024-01-01",
"end": "2024-12-31"
}
}
}
Response:
{
"status": "success",
"results": {
"summary": {
"count": 15847,
"mean": 151.52,
"median": 145.00,
"std": 42.18
},
"quartiles": {
"q1": 120.00,
"q2": 145.00,
"q3": 180.00
},
"by_category": [...]
},
"execution_time_ms": 234
}
POST /analytics/predictive
Generate predictions using machine learning models
Request Body:
{
"model_type": "linear_regression",
"training_data": {
"dataset_id": "string",
"features": ["feature1", "feature2"],
"target": "revenue"
},
"prediction_config": {
"horizon": 30,
"interval": "day",
"confidence_level": 0.95
}
}
Response:
{
"status": "success",
"model_id": "model_abc123",
"predictions": [
{
"date": "2025-01-01",
"value": 24500,
"confidence_interval": {
"lower": 23300,
"upper": 25700
}
}
],
"metrics": {
"r2_score": 0.89,
"rmse": 12400,
"mae": 9800
}
}
POST /analytics/diagnostic
Perform diagnostic analysis to understand causation
Request Body:
{
"dataset_id": "string",
"target_metric": "revenue",
"potential_factors": [
"marketing_spend",
"seasonality",
"pricing"
],
"analysis_type": "correlation"
}
Response:
{
"status": "success",
"correlations": [
{
"factor": "marketing_spend",
"correlation": 0.78,
"p_value": 0.001,
"significance": "high"
}
],
"root_causes": [
{
"factor": "new_product_launch",
"contribution": 0.42,
"impact": "+$45,000"
}
]
}
POST /analytics/prescriptive
Get actionable recommendations based on data
Request Body:
{
"objective": "maximize_revenue",
"constraints": {
"budget": 100000,
"resources": ["staff", "inventory"]
},
"variables": [
"marketing_budget",
"pricing",
"inventory_levels"
]
}
Response:
{
"status": "success",
"recommendations": [
{
"action": "increase_marketing_budget",
"change": "+18%",
"expected_roi": 3.2,
"confidence": 0.85
}
],
"optimal_solution": {
"marketing_budget": 118000,
"pricing": 159,
"expected_outcome": "+$125,000 revenue"
}
}
🎯 Segmentation Endpoints
POST /segmentation/cluster
Perform customer or data segmentation
Request Body:
{
"dataset_id": "string",
"algorithm": "kmeans",
"n_clusters": 4,
"features": [
"purchase_frequency",
"average_spend",
"recency"
]
}
Response:
{
"status": "success",
"clusters": [
{
"cluster_id": 0,
"name": "High Value",
"size": 1234,
"centroid": {
"purchase_frequency": 12,
"average_spend": 450,
"recency": 7
}
}
],
"metrics": {
"silhouette_score": 0.72,
"inertia": 15234
}
}
⚡ Real-time Analytics
POST /stream/create
Create a real-time analytics stream
Request Body:
{
"stream_name": "sales_events",
"source": {
"type": "kafka",
"topic": "transactions",
"brokers": ["broker1:9092"]
},
"analytics": {
"window": "5m",
"aggregations": ["count", "sum", "avg"]
}
}
Response:
{
"status": "success",
"stream_id": "stream_xyz789",
"websocket_url": "wss://api.wia.org/stream/xyz789",
"status": "active"
}
GET /stream/{stream_id}/metrics
Get metrics for a running stream
Response:
{
"stream_id": "stream_xyz789",
"status": "running",
"metrics": {
"events_processed": 15847,
"events_per_second": 142,
"avg_latency_ms": 23,
"anomalies_detected": 3
},
"last_updated": "2025-01-15T10:30:00Z"
}
⚠️ Error Handling
The API uses standard HTTP status codes and returns errors in this format:
{
"status": "error",
"error": {
"code": "INVALID_DATASET",
"message": "Dataset not found or inaccessible",
"details": {
"dataset_id": "abc123"
}
},
"timestamp": "2025-01-15T10:30:00Z"
}
Common Error Codes
| Code |
HTTP Status |
Description |
INVALID_DATASET |
404 |
Dataset not found |
INSUFFICIENT_DATA |
400 |
Not enough data for analysis |
MODEL_TRAINING_FAILED |
500 |
ML model training failed |
RATE_LIMIT_EXCEEDED |
429 |
Too many requests |
UNAUTHORIZED |
401 |
Invalid or missing API key |