事件 API (Event)
事件 API (Event API) 允许你追踪随时间发生的有状态事件。与简单的消息不同,事件具有生命周期(开始 -> 更新 -> 关闭)。
接口端点 (Endpoints)
Section titled “接口端点 (Endpoints)”| 动作 | 方法 | 路径 |
|---|---|---|
| 创建 (Create) | POST | /v1/channel/{channel_id}/event/create |
| 更新 (Update) | POST | /v1/channel/{channel_id}/event/update |
| 关闭 (Close) | POST | /v1/channel/{channel_id}/event/close |
请求头 (Headers)
Section titled “请求头 (Headers)”| 参数名 | 值 | 描述 |
|---|---|---|
Content-Type | application/json | 必填。 |
Authorization | Bearer <token> | 你的网关秘钥令牌。 |
| 字段名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
password | string | 是 | 频道密码 (8-128 个字符)。 |
event_id | string | 否* | 事件的唯一 ID。在 更新 和 关闭 时为必填。如果在 创建 时未提供,系统会返回一个随机 ID。 |
event_type | string | 是 | 事件类型分类(如:motion_detected, system_backup)。 |
severity | enum | 否 | critical, high, normal, low。 |
attrs | object | 否 | 包含事件特定数据的 JSON 对象(如:{ "battery": 80 })。 |
1. 创建事件 (Create Event)
Section titled “1. 创建事件 (Create Event)”初始化一个新的事件。
curl -X POST https://api.pushgo.io/v1/channel/ABC123XYZ/event/create \ -H "Content-Type: application/json" \ -d '{ "password": "your_password", "event_type": "door_open", "severity": "high", "started_at": 1672531200 }'2. 更新事件 (Update Event)
Section titled “2. 更新事件 (Update Event)”向正在进行的事件添加新信息。新的 attrs 将与现有的 attrs 进行合并。
curl -X POST https://api.pushgo.io/v1/channel/ABC123XYZ/event/update \ -H "Content-Type: application/json" \ -d '{ "password": "your_password", "event_id": "PREVIOUSLY_CREATED_ID", "attrs": { "still_open": true } }'3. 关闭事件 (Close Event)
Section titled “3. 关闭事件 (Close Event)”标记事件已结束。
curl -X POST https://api.pushgo.io/v1/channel/ABC123XYZ/event/close \ -H "Content-Type: application/json" \ -d '{ "password": "your_password", "event_id": "PREVIOUSLY_CREATED_ID", "ended_at": 1672534800 }'成功的请求会返回 event_id:
{ "event_id": "550e8400-e29b-41d4-a716-446655440000"}