实体 API (Thing)
实体 API (Thing API) 允许你管理持久化的实体,例如物理设备、房间或逻辑任务。与事件不同,实体具有长期的状态,并可以保存静态属性。
接口端点 (Endpoints)
Section titled “接口端点 (Endpoints)”| 动作 | 方法 | 路径 |
|---|---|---|
| 创建 (Create) | POST | /v1/channel/{channel_id}/thing/create |
| 更新 (Update) | POST | /v1/channel/{channel_id}/thing/update |
| 归档 (Archive) | POST | /v1/channel/{channel_id}/thing/archive |
| 删除 (Delete) | POST | /v1/channel/{channel_id}/thing/delete |
请求头 (Headers)
Section titled “请求头 (Headers)”| 参数名 | 值 | 描述 |
|---|---|---|
Content-Type | application/json | 必填。 |
Authorization | Bearer <token> | 你的网关秘钥令牌。 |
| 字段名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
password | string | 是 | 频道密码 (8-128 个字符)。 |
thing_id | string | 否* | 实体的唯一 ID。在 更新、归档 和 删除 时为必填。 |
thing_type | string | 是 | 实体类型分类(如:thermometer, web_server)。 |
state | enum | 否 | 实体的状态:ACTIVE (活跃), INACTIVE (不活跃), DECOMMISSIONED (已退役)。 |
attrs | object | 否 | 包含当前属性的 JSON 对象(如:{ "firmware": "1.0.2" })。 |
1. 创建实体 (Create Thing)
Section titled “1. 创建实体 (Create Thing)”初始化一个新的持久化实体。
curl -X POST https://api.pushgo.io/v1/channel/ABC123XYZ/thing/create \ -H "Content-Type: application/json" \ -d '{ "password": "your_password", "thing_id": "living_room_temp", "thing_type": "sensor", "state": "ACTIVE", "attrs": { "location": "Floor 1" } }'2. 更新实体 (Update Thing)
Section titled “2. 更新实体 (Update Thing)”修改现有实体的属性或状态。属性 (attrs) 将进行合并更新。
curl -X POST https://api.pushgo.io/v1/channel/ABC123XYZ/thing/update \ -H "Content-Type: application/json" \ -d '{ "password": "your_password", "thing_id": "living_room_temp", "attrs": { "temperature": 22.5, "humidity": 45 } }'3. 归档 / 删除 (Archive / Delete)
Section titled “3. 归档 / 删除 (Archive / Delete)”- 归档 (Archive): 保留数据,但在 App 的主视图中隐藏。
- 删除 (Delete): 永久移除该实体及其历史记录。
curl -X POST https://api.pushgo.io/v1/channel/ABC123XYZ/thing/archive \ -H "Content-Type: application/json" \ -d '{ "password": "your_password", "thing_id": "living_room_temp" }'成功的请求会返回 thing_id:
{ "thing_id": "living_room_temp"}