Alerts API
Alerts API
Section titled “Alerts API”Create and manage alert rules programmatically.
List Alert Rules
Section titled “List Alert Rules”Get all alert rules.
GET /v1/alertsQuery Parameters
Section titled “Query Parameters”| Parameter | Type | Description |
|---|---|---|
page | number | Page number |
limit | number | Items per page |
device_id | string | Filter by device |
enabled | boolean | Filter by status |
Example Request
Section titled “Example Request”curl -X GET "https://api.siliconwit.io/v1/alerts" \ -H "Authorization: Bearer YOUR_API_KEY"Example Response
Section titled “Example Response”{ "success": true, "data": [ { "id": "alert_abc123", "name": "High Temperature", "device_id": "dev_abc123", "condition": { "field": "temperature", "operator": "gt", "value": 35 }, "actions": ["email"], "enabled": true, "created_at": "2024-01-01T00:00:00Z" } ]}Create Alert Rule
Section titled “Create Alert Rule”Create a new alert rule.
POST /v1/alertsRequest Body
Section titled “Request Body”| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Alert name |
device_id | string | Yes | Device to monitor |
condition | object | Yes | Trigger condition |
actions | array | Yes | Notification actions |
severity | string | No | info, warning, critical |
cooldown | number | No | Seconds between alerts |
Condition Object
Section titled “Condition Object”| Field | Type | Description |
|---|---|---|
field | string | Data field to monitor |
operator | string | gt, lt, eq, ne, between |
value | any | Threshold value |
duration | number | Sustained seconds |
Example Request
Section titled “Example Request”curl -X POST "https://api.siliconwit.io/v1/alerts" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "High Temperature Alert", "device_id": "dev_abc123", "condition": { "field": "temperature", "operator": "gt", "value": 35, "duration": 300 }, "actions": ["email", "webhook"], "severity": "critical", "cooldown": 3600 }'Example Response
Section titled “Example Response”{ "success": true, "data": { "id": "alert_xyz789", "name": "High Temperature Alert", "device_id": "dev_abc123", "condition": { "field": "temperature", "operator": "gt", "value": 35, "duration": 300 }, "actions": ["email", "webhook"], "severity": "critical", "cooldown": 3600, "enabled": true, "created_at": "2024-01-15T15:00:00Z" }}Update Alert Rule
Section titled “Update Alert Rule”Modify an existing alert rule.
PUT /v1/alerts/:idExample Request
Section titled “Example Request”curl -X PUT "https://api.siliconwit.io/v1/alerts/alert_xyz789" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "condition": { "field": "temperature", "operator": "gt", "value": 40 }, "enabled": true }'Delete Alert Rule
Section titled “Delete Alert Rule”Remove an alert rule.
DELETE /v1/alerts/:idExample Request
Section titled “Example Request”curl -X DELETE "https://api.siliconwit.io/v1/alerts/alert_xyz789" \ -H "Authorization: Bearer YOUR_API_KEY"Enable/Disable Alert
Section titled “Enable/Disable Alert”Toggle alert status.
POST /v1/alerts/:id/enablePOST /v1/alerts/:id/disableExample Request
Section titled “Example Request”curl -X POST "https://api.siliconwit.io/v1/alerts/alert_xyz789/disable" \ -H "Authorization: Bearer YOUR_API_KEY"Alert History
Section titled “Alert History”Get triggered alert history.
GET /v1/alerts/historyQuery Parameters
Section titled “Query Parameters”| Parameter | Type | Description |
|---|---|---|
from | string | Start time |
to | string | End time |
alert_id | string | Filter by alert rule |
device_id | string | Filter by device |
severity | string | Filter by severity |
acknowledged | boolean | Filter by ack status |
Example Request
Section titled “Example Request”curl -X GET "https://api.siliconwit.io/v1/alerts/history?\from=2024-01-01&severity=critical" \ -H "Authorization: Bearer YOUR_API_KEY"Example Response
Section titled “Example Response”{ "success": true, "data": [ { "id": "event_abc123", "alert_id": "alert_xyz789", "alert_name": "High Temperature Alert", "device_id": "dev_abc123", "device_name": "Office Sensor", "condition": "temperature > 35", "value": 38.5, "severity": "critical", "triggered_at": "2024-01-15T14:30:00Z", "acknowledged": true, "acknowledged_at": "2024-01-15T14:35:00Z", } ]}Acknowledge Alert
Section titled “Acknowledge Alert”Mark an alert event as acknowledged.
POST /v1/alerts/history/:event_id/acknowledgeRequest Body
Section titled “Request Body”| Field | Type | Description |
|---|---|---|
note | string | Optional note |
Example Request
Section titled “Example Request”curl -X POST "https://api.siliconwit.io/v1/alerts/history/event_abc123/acknowledge" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "note": "Checked sensor, was near heat source" }'Condition Operators
Section titled “Condition Operators”| Operator | Description | Example |
|---|---|---|
gt | Greater than | > 35 |
gte | Greater than or equal | >= 35 |
lt | Less than | < 10 |
lte | Less than or equal | <= 10 |
eq | Equals | = 100 |
ne | Not equals | != 0 |
between | Between range | [20, 30] |
outside | Outside range | not [20, 30] |
Action Types
Section titled “Action Types”| Action | Description | Plan |
|---|---|---|
email | Send email | All |
sms | Send SMS | Business+ |
webhook | Call URL | All |
push | Push notification | Coming soon |
Webhook Payload
Section titled “Webhook Payload”When using webhook action:
{ "alert_id": "alert_xyz789", "alert_name": "High Temperature Alert", "device_id": "dev_abc123", "device_name": "Office Sensor", "condition": "temperature > 35", "current_value": 38.5, "severity": "critical", "triggered_at": "2024-01-15T14:30:00Z", "dashboard_url": "https://siliconwit.io/dashboard/devices/dev_abc123"}Error Codes
Section titled “Error Codes”| Code | Description |
|---|---|
ALERT_NOT_FOUND | Alert ID doesn’t exist |
INVALID_CONDITION | Malformed condition object |
INVALID_OPERATOR | Unknown operator |
DEVICE_NOT_FOUND | Referenced device doesn’t exist |