跳转到内容

实体 API (Thing)

实体 API (Thing API) 允许你管理持久化的实体,例如物理设备、房间或逻辑任务。与事件不同,实体具有长期的状态,并可以保存静态属性。

动作方法路径
创建 (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

参数名描述
Content-Typeapplication/json必填。
AuthorizationBearer <token>你的网关秘钥令牌。

字段名类型是否必填描述
passwordstring频道密码 (8-128 个字符)。
thing_idstring否*实体的唯一 ID。在 更新归档删除 时为必填。
thing_typestring实体类型分类(如:thermometer, web_server)。
stateenum实体的状态:ACTIVE (活跃), INACTIVE (不活跃), DECOMMISSIONED (已退役)。
attrsobject包含当前属性的 JSON 对象(如:{ "firmware": "1.0.2" })。

初始化一个新的持久化实体。

Terminal window
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" }
}'

修改现有实体的属性或状态。属性 (attrs) 将进行合并更新。

Terminal window
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 }
}'
  • 归档 (Archive): 保留数据,但在 App 的主视图中隐藏。
  • 删除 (Delete): 永久移除该实体及其历史记录。
Terminal window
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"
}