跳到內容

實體 API (Thing)

Thing API 用於表達長期存在並重複更新的物件,例如伺服器、房間、感測器、網路服務或長期任務。建立實體後,Gateway 傳回 thing_id;後續更新、歸檔和刪除都透過這個 ID 關聯到同一個物件。

POST /thing/create
POST /thing/update
POST /thing/archive
POST /thing/delete

請求 body必須是 JSON,未宣告欄位會被嚴格拒絕。私人 Gateway 如果啟用了 PUSHGO_TOKEN,還需要 Authorization: Bearer <token>

Header必填說明
Content-Type: application/json請求 body格式。
Authorization: Bearer <token>視 Gateway 設定而定僅私人 Gateway 開啟 PUSHGO_TOKEN 時必填。
/thing/create -> thing_id
|
+-> /thing/update 可呼叫多次
|
+-> /thing/archive 歸檔但保留歷史
|
+-> /thing/delete 刪除或退役
欄位型別必填說明
channel_idstring目標 Channel ID。
passwordstringChannel 密碼,通常 8-128 個字元。
op_idstring冪等鍵;不傳則 Gateway 會自動產生並在回應中傳回。
ciphertextstring可選 E2EE 密文載重。
路由必填業務欄位
/thing/createobserved_at
/thing/updatething_idobserved_at
/thing/archivething_idobserved_at
/thing/deletething_idobserved_at
欄位型別規則
thing_idstring更新、歸檔和刪除必填;建立時不能傳,由 Gateway 生成。
titlestring建立時建議傳;當前 Gateway 不因缺少 title 拒絕建立。
descriptionstring可選;空字串依預設處理。
tagsstring[]最多 32 項,每項最多 64 字元,trim 後去重。
primary_imagestring可選 URL,最大 2048 字元。
imagesstring[]最多 32 項,每項最多 2048 字元,trim 後去重。
created_atnumber僅 create 允許;不傳時回退為 observed_at
deleted_atnumber僅 delete 允許;不傳時回退為 observed_at
observed_atnumber必填;本次狀態觀測時間,Unix 毫秒時間戳記。
external_idsobjectkey 僅允許 [A-Za-z0-9_:.\-],key <= 64;value 僅 stringnull
location_type + location_valuestring + string必須成對出現;location_type 僅允許 physicalgeoclouddatacenterlogical
attrsobject物件補丁;value 為 null 表示刪鍵;不允許陣列;物件巢狀僅支援一層。
metadataobject僅支援標量值;key <= 64,value <= 512。
Terminal window
curl -X POST https://gateway.pushgo.cn/thing/create \
-H "Content-Type: application/json" \
-d '{
"channel_id": "YOUR_CHANNEL_ID",
"password": "YOUR_CHANNEL_PASSWORD",
"title": "家庭 NAS",
"description": "客廳機櫃中的主儲存",
"observed_at": 1713750000000,
"tags": ["nas", "home"],
"location_type": "physical",
"location_value": "home/living-room",
"attrs": {
"online": true,
"disk_used": 0.72,
"temperature": 43.2
}
}'

響應:

{
"success": true,
"data": {
"channel_id": "YOUR_CHANNEL_ID",
"op_id": "op-20260422-001",
"thing_id": "8a1fc4b3d9f04fd2857f92f66f7cc5d1",
"accepted": true
},
"error": null,
"error_code": null
}

儲存傳回的 thing_id,後續更新、歸檔和刪除都需要它。

Terminal window
curl -X POST https://gateway.pushgo.cn/thing/update \
-H "Content-Type: application/json" \
-d '{
"channel_id": "YOUR_CHANNEL_ID",
"password": "YOUR_CHANNEL_PASSWORD",
"thing_id": "8a1fc4b3d9f04fd2857f92f66f7cc5d1",
"observed_at": 1713750600000,
"attrs": {
"disk_used": 0.74,
"temperature": 44.1
}
}'

attrs 是補丁,不需要每次都傳完整狀態。要刪除某個鍵,可以傳 null

{
"attrs": {
"temporary_alarm": null
}
}

歸檔適合「不再活躍,但仍希望保留歷史」的物件。

Terminal window
curl -X POST https://gateway.pushgo.cn/thing/archive \
-H "Content-Type: application/json" \
-d '{
"channel_id": "YOUR_CHANNEL_ID",
"password": "YOUR_CHANNEL_PASSWORD",
"thing_id": "8a1fc4b3d9f04fd2857f92f66f7cc5d1",
"observed_at": 1713751200000,
"attrs": {
"online": false
}
}'

刪除或退役實體時使用 /thing/delete

Terminal window
curl -X POST https://gateway.pushgo.cn/thing/delete \
-H "Content-Type: application/json" \
-d '{
"channel_id": "YOUR_CHANNEL_ID",
"password": "YOUR_CHANNEL_PASSWORD",
"thing_id": "8a1fc4b3d9f04fd2857f92f66f7cc5d1",
"observed_at": 1713751800000,
"deleted_at": 1713751800000
}'

Thing 表示長期物件。相關警告可以用 Message 關聯到 thing_id,相關過程可以用 Event 關聯到 thing_id

場景推薦建模
NAS 目前 CPU、溫度、磁碟使用率Thing
NAS 磁碟快滿的一次提醒Message + thing_id
NAS 備份從開始到完成Event + thing_id

Thing API 回應同樣使用統一 envelope。 accepted=true 表示 Gateway 已進入分發流程,不保證所有裝置都已經展示系統通知。

狀態碼典型原因
400缺少 observed_at、傳了未知欄位、attrsexternal_ids 格式不合法。
401私人 Gateway Bearer Token 缺失或錯誤。
404Channel 或 thing_id 不存在。
413請求 body超過 32KB。
503分發未完整成功。