跳到內容

實體 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 密碼;先 trim,再按 8-128 位元組驗證。
op_idstring必須省略由 Gateway 產生並傳回;客戶端傳入會傳回 400 op_id_not_allowed
ciphertextstring可選 E2EE 密文載重。
路由必填業務欄位
/thing/createobserved_at
/thing/updatething_idobserved_at
/thing/archivething_idobserved_at
/thing/deletething_idobserved_at
欄位型別規則
thing_idstringupdate/archive/delete 必填;create 時不得傳入;1-64 個字元,可用字母、數字、_:-
titledescriptionstring可選 patch 內容;建立時建議提供 title,但 Gateway 不因缺少而拒絕。
tagsimagesstring[]可選 patch 內容;不繼承 Message 的數量和長度限制。
primary_imagelocation_typelocation_valuestring可選 patch 內容;1.3.0 不強制先前文件中的位置成對和格式規則。
created_atnumber 或數字字串可選且僅用於 create;未傳入時不寫入,也不會從 observed_at 回填。
deleted_atnumber 或數字字串可選且僅用於 delete;未傳入時不寫入,也不會從 observed_at 回填;create/update/archive 會拒絕。
observed_atnumber 或數字字串必填;接受 Unix 秒或毫秒並正規化為毫秒。
external_idsattrsobject可選 patch 內容;1.3.0 不強制先前文件中的結構限制。
metadataobject自訂標量鍵值;key <= 64 位元組,非空標量文字 <= 512 位元組;拒絕巢狀物件、陣列和 null。

create 禁止 thing_id;所有動作禁止客戶端傳入 stateop_iddeleted_at 僅用於 delete。未知欄位會被忽略且不會生效。

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": {
"op_id": "00191f23cc000-0123456789abcdef0123456789abcdef",
"thing_id": "8a1fc4b3d9f04fd2857f92f66f7cc5d1"
}
}

儲存傳回的 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

統一成功 envelope 表示 Gateway 已持久受理,不代表供應商投遞或裝置顯示成功。可用傳回的 op_id 查詢 GET /send_status/{op_id}

狀態碼典型原因
400路由級必填欄位缺失、ID/時間/metadata 無效、傳入 op_id 或動作禁止欄位。
401私人 Gateway Bearer Token 缺失或錯誤。
404Channel 不存在或憑證不相符。
413請求 body 超過 32 KiB(32,768 位元組)。
503Gateway 無法受理本次提交。