接入教程
1. 在Instatus官网注册并获取API密钥
2. 使用HTTP POST请求向指定端点发送维护事件
3. 通过PUT请求更新现有事件状态
4. 调用GET接口查看历史事件记录
发布事故报告
python
import requests
url = "https://api.instatus.com/v1/incidents"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"name": "API服务中断",
"status": "INVESTIGATING",
"affected_components": ["api", "database"],
"body": "我们正在调查API服务的间歇性中断问题。"
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
获取所有维护事件
php
<?php
$url = 'https://api.instatus.com/v1/maintenances';
$apiKey = 'YOUR_API_KEY';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
print_r($data);
?>
更新事故状态
javascript
const fetch = require('node-fetch');
const url = 'https://api.instatus.com/v1/incidents/incident-id';
const options = {
method: 'PUT',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"status": "RESOLVED",
"body": "问题已解决,服务恢复正常。"
})
};
fetch(url, options)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
常见问题
如何获取API密钥?
请登录您的Instatus账户,在设置菜单的API部分生成新的API密钥。请妥善保管此密钥,不要泄露给他人。
API请求有速率限制吗?
是的,API设有速率限制以保障服务稳定性。具体限制请参考官方文档,建议合理控制请求频率并在代码中实现适当的重试逻辑。
支持哪些类型的事件状态?
Instatus API支持多种事件状态,例如:调查中(INVESTIGATING)、已识别(IDENTIFIED)、监控中(MONITORING)、已解决(RESOLVED)等。具体状态值请查阅API文档。
Aitishiku.com