REST Endpoints
Complete reference for the TwinEdge REST API. All endpoints are prefixed with https://api.twinedgeai.com/v1.
Base URL
https://api.twinedgeai.com/v1
Common Headers
All requests should include:
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Accept: application/json
Response Format
All responses follow this structure:
Success:
{
"data": { ... },
"meta": {
"page": 1,
"per_page": 20,
"total": 100
}
}
Error:
{
"error": {
"code": "validation_error",
"message": "Invalid input",
"details": [
{"field": "name", "message": "Name is required"}
]
}
}
Data Sources
List Data Sources
GET /data-sources
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
type | string | Filter by type (opcua, modbus, mqtt) |
status | string | Filter by status (connected, disconnected) |
page | integer | Page number (default: 1) |
per_page | integer | Items per page (default: 20, max: 100) |
Response:
{
"data": [
{
"id": "ds-123",
"name": "Factory OPC UA Server",
"type": "opcua",
"endpoint": "opc.tcp://192.168.1.100:4840",
"status": "connected",
"tag_count": 45,
"created_at": "2026-01-01T00:00:00Z"
}
]
}
Create Data Source
POST /data-sources
Request Body:
{
"name": "Production Line PLC",
"type": "modbus",
"config": {
"host": "192.168.1.50",
"port": 502,
"unit_id": 1
}
}
Get Data Source
GET /data-sources/{id}
Update Data Source
PUT /data-sources/{id}
Delete Data Source
DELETE /data-sources/{id}
Test Connection
POST /data-sources/{id}/test
Telemetry
Query Telemetry
GET /telemetry
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
data_source_id | string | Filter by data source |
asset_id | string | Filter by asset |
tag_name | string | Filter by tag |
start | ISO8601 | Start time |
end | ISO8601 | End time |
aggregation | string | avg, min, max, sum, count |
interval | string | 1m, 5m, 1h, 1d |
Response:
{
"data": [
{
"timestamp": "2026-01-06T10:00:00Z",
"asset_id": "Pump_001",
"tag_name": "temperature",
"value": 65.5,
"quality": "good"
}
]
}
Ingest Telemetry
POST /telemetry
Request Body:
{
"data": [
{
"asset_id": "Pump_001",
"tag_name": "temperature",
"value": 65.5,
"timestamp": "2026-01-06T10:00:00Z"
}
]
}
Get Latest Values
GET /telemetry/latest
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
asset_id | string | Required - Asset ID |
tags | string | Comma-separated tag names |
Dashboards
List Dashboards
GET /dashboards
Create Dashboard
POST /dashboards
Request Body:
{
"name": "Pump Monitoring",
"description": "Real-time pump health dashboard",
"layout": {
"columns": 24,
"widgets": [...]
}
}
Get Dashboard
GET /dashboards/{id}
Update Dashboard
PUT /dashboards/{id}
Delete Dashboard
DELETE /dashboards/{id}
Duplicate Dashboard
POST /dashboards/{id}/duplicate
Alerts
List Alert Rules
GET /alert-rules
Create Alert Rule
POST /alert-rules
Request Body:
{
"name": "High Temperature",
"severity": "warning",
"data_source_id": "ds-123",
"condition": {
"tag_name": "temperature",
"operator": "gt",
"value": 80,
"duration_seconds": 60
},
"notifications": ["email", "slack"]
}
Get Alert Rule
GET /alert-rules/{id}
Update Alert Rule
PUT /alert-rules/{id}
Delete Alert Rule
DELETE /alert-rules/{id}
Enable/Disable Alert Rule
POST /alert-rules/{id}/enable
POST /alert-rules/{id}/disable
List Active Alerts
GET /alerts
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
status | string | active, acknowledged, resolved |
severity | string | critical, warning, info |
start | ISO8601 | Start time |
end | ISO8601 | End time |
Acknowledge Alert
POST /alerts/{id}/acknowledge
Request Body:
{
"note": "Investigating the issue"
}
Resolve Alert
POST /alerts/{id}/resolve
ML Models
List Datasets
GET /ml/datasets
Create Dataset
POST /ml/datasets
Upload Dataset File
POST /ml/datasets/{id}/upload
Content-Type: multipart/form-data
Get Dataset Preview
GET /ml/datasets/{id}/preview
List Training Jobs
GET /ml/training
Start Training Job
POST /ml/training
Request Body:
{
"name": "Pump Anomaly Detector",
"dataset_id": "ds-456",
"algorithm": "isolation_forest",
"hyperparameters": {
"n_estimators": 100,
"contamination": 0.05
}
}
Get Training Job Status
GET /ml/training/{id}
Cancel Training Job
DELETE /ml/training/{id}
List Models
GET /ml/models
Get Model
GET /ml/models/{id}
Test Model
POST /ml/models/{id}/test
Request Body:
{
"features": {
"vibration_x": 2.5,
"vibration_y": 2.1,
"temperature": 65.0
}
}
Deploy Model
POST /ml/models/{id}/deploy