Data API
Data API
Section titled “Data API”Query historical data and push data points via the REST API.
Query Data
Section titled “Query Data”Retrieve telemetry data from a device.
GET /v1/devices/:id/dataQuery Parameters
Section titled “Query Parameters”| Parameter | Type | Description |
|---|---|---|
from | string | Start time (ISO 8601) |
to | string | End time (ISO 8601) |
fields | string | Comma-separated field names |
aggregation | string | avg, min, max, sum, count |
interval | string | 1m, 5m, 1h, 1d |
limit | number | Max data points (default: 1000) |
Example Request
Section titled “Example Request”curl -X GET "https://api.siliconwit.io/v1/devices/dev_abc123/data?\from=2024-01-01T00:00:00Z&\to=2024-01-02T00:00:00Z&\fields=temperature,humidity&\aggregation=avg&\interval=1h" \ -H "Authorization: Bearer YOUR_API_KEY"Example Response
Section titled “Example Response”{ "success": true, "data": { "device_id": "dev_abc123", "from": "2024-01-01T00:00:00Z", "to": "2024-01-02T00:00:00Z", "aggregation": "avg", "interval": "1h", "points": [ { "timestamp": "2024-01-01T00:00:00Z", "temperature": 24.5, "humidity": 55 }, { "timestamp": "2024-01-01T01:00:00Z", "temperature": 24.2, "humidity": 56 }, { "timestamp": "2024-01-01T02:00:00Z", "temperature": 23.8, "humidity": 58 } ] }}Get Latest Data
Section titled “Get Latest Data”Get the most recent data point.
GET /v1/devices/:id/data/latestExample Request
Section titled “Example Request”curl -X GET "https://api.siliconwit.io/v1/devices/dev_abc123/data/latest" \ -H "Authorization: Bearer YOUR_API_KEY"Example Response
Section titled “Example Response”{ "success": true, "data": { "timestamp": "2024-01-15T14:30:00Z", "temperature": 25.5, "humidity": 60, "battery": 85 }}Push Data
Section titled “Push Data”Send data via REST API (alternative to MQTT).
POST /v1/devices/:id/dataRequest Body
Section titled “Request Body”| Field | Type | Required | Description |
|---|---|---|---|
timestamp | string | No | ISO 8601 timestamp (default: now) |
* | any | Yes | Data fields |
Example Request
Section titled “Example Request”curl -X POST "https://api.siliconwit.io/v1/devices/dev_abc123/data" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "temperature": 25.5, "humidity": 60, "battery": 85 }'Example Response
Section titled “Example Response”{ "success": true, "data": { "id": "dp_abc123", "timestamp": "2024-01-15T14:35:00Z", "received": true }}Batch Push
Section titled “Batch Push”Send multiple data points at once.
POST /v1/devices/:id/data/batchRequest Body
Section titled “Request Body”{ "points": [ { "timestamp": "2024-01-15T14:30:00Z", "temperature": 25.5 }, { "timestamp": "2024-01-15T14:31:00Z", "temperature": 25.6 }, { "timestamp": "2024-01-15T14:32:00Z", "temperature": 25.4 } ]}Example Request
Section titled “Example Request”curl -X POST "https://api.siliconwit.io/v1/devices/dev_abc123/data/batch" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "points": [ {"timestamp": "2024-01-15T14:30:00Z", "temperature": 25.5}, {"timestamp": "2024-01-15T14:31:00Z", "temperature": 25.6} ] }'Example Response
Section titled “Example Response”{ "success": true, "data": { "received": 2, "failed": 0 }}Export Data
Section titled “Export Data”Export data in various formats.
GET /v1/devices/:id/data/exportQuery Parameters
Section titled “Query Parameters”| Parameter | Type | Description |
|---|---|---|
from | string | Start time (ISO 8601) |
to | string | End time (ISO 8601) |
format | string | csv, json, xlsx |
Example Request
Section titled “Example Request”curl -X GET "https://api.siliconwit.io/v1/devices/dev_abc123/data/export?\from=2024-01-01&to=2024-01-31&format=csv" \ -H "Authorization: Bearer YOUR_API_KEY" \ -o data.csvAggregation Functions
Section titled “Aggregation Functions”| Function | Description |
|---|---|
avg | Average value |
min | Minimum value |
max | Maximum value |
sum | Sum of values |
count | Number of points |
first | First value |
last | Last value |
Time Intervals
Section titled “Time Intervals”| Interval | Description |
|---|---|
1m | 1 minute |
5m | 5 minutes |
15m | 15 minutes |
1h | 1 hour |
6h | 6 hours |
1d | 1 day |
1w | 1 week |
Data Retention
Section titled “Data Retention”| Plan | Retention |
|---|---|
| Starter | 7 days |
| Business | 90 days |
| Enterprise | Custom |
Data older than retention period is automatically deleted.
Error Codes
Section titled “Error Codes”| Code | Description |
|---|---|
INVALID_TIME_RANGE | from must be before to |
TIME_RANGE_TOO_LARGE | Max range is 1 year |
INVALID_AGGREGATION | Unknown aggregation function |
DATA_NOT_FOUND | No data in time range |