import requests
API_KEY = "rbtk_xxx"
BASE = "https://api.roboticks.io/api/v1"
headers = {"Authorization": f"Bearer {API_KEY}"}
# Create Slack integration
slack = requests.post(
f"{BASE}/organizations/acme/projects/warehouse/integrations",
headers=headers,
json={
"type": "slack",
"name": "Alerts",
"config": {
"webhook_url": "https://hooks.slack.com/services/xxx"
}
}
).json()
# Test the integration
test = requests.post(
f"{BASE}/organizations/acme/projects/warehouse/integrations/{slack['id']}/test",
headers=headers
).json()
print(f"Test result: {test['success']}")
# Create alert rule using this integration
rule = requests.post(
f"{BASE}/organizations/acme/projects/warehouse/alert-rules",
headers=headers,
json={
"name": "Device Offline Alert",
"condition": {
"type": "device_status",
"status": "offline",
"duration_seconds": 300
},
"severity": "critical",
"integration_ids": [slack["id"]],
"enabled": True
}
).json()