设备
替换
id 和令牌需要替换为自己的 获取令牌
获取设备列表
GET /v1/devices
▶️ 示例
js
var res = http.request('https://api.hamibot.com/v1/devices', {
method: 'GET',
headers: {
authorization: '你的令牌(hmp 开头)',
},
});
log(res.body.json());
shell
curl -H "Authorization: 你的令牌(hmp 开头)" \
https://api.hamibot.com/v1/devices
✅ 响应
200 成功
json
{
"count": 1,
"items": [
{
"_id": "a51d237e9af41ecc021c9ff6",
"online": true,
"tags": ["tag1", "tag2"],
"name": "零号机",
"brand": "Xiaomi",
"model": "MI 11"
}
]
}
获取设备
GET /v1/devices/设备_id
▶️ 示例
js
var res = http.request('https://api.hamibot.com/v1/devices/设备_id', {
method: 'GET',
headers: {
authorization: '你的令牌(hmp 开头)',
},
});
log(res.body.json());
shell
curl -H "Authorization: 你的令牌(hmp 开头)" \
https://api.hamibot.com/v1/devices/设备_id
✅ 响应
200 成功
json
{
"_id": "a51d237e9af41ecc021c9ff6",
"online": true,
"tags": ["tag1", "tag2"],
"name": "零号机",
"brand": "Xiaomi",
"model": "MI 11"
}
修改设备
PUT /v1/devices/设备_id
参数
名称 | 类型 | 描述 |
---|---|---|
name | string | 设备名字,最大长度 20 字符 |
tags | [string] | 设备标签,标签最大长度 10 字符,标签数量最多 1 个 |
▶️ 示例
shell
curl \
-X PUT \
-H "Authorization: 你的令牌(hmp 开头)" \
-d '{"name": "新的设备名字", "tags": ["新的标签"]}' \
https://api.hamibot.com/v1/devices/设备_id
✅ 响应
204 成功
删除设备
DELETE /v1/devices/设备_id
▶️ 示例
js
var res = http.request('https://api.hamibot.com/v1/devices/设备_id', {
method: 'DELETE',
headers: {
authorization: '你的令牌(hmp 开头)',
},
});
shell
curl \
-X DELETE \
-H "Authorization: 你的令牌(hmp 开头)" \
-H "Content-Type: application/json" \
https://api.hamibot.com/v1/devices/设备_id
✅ 响应
204 成功
停止所有脚本
PUT /v1/devices/设备_id/stop
▶️ 示例
js
http.request('https://api.hamibot.com/v1/devices/设备_id/stop', {
method: 'PUT',
headers: {
authorization: '你的令牌(hmp 开头)',
},
});
shell
curl -X PUT -H "Authorization: 你的令牌(hmp 开头)" \
https://api.hamibot.com/v1/devices/设备_id/stop
✅ 响应
204 成功
消息推送
版本要求
最低版本要求:Hamibot 1.2.2 下载最新版
INFO
贡献者 sl1097643327git
POST /v1/devices/设备_id/messages
参数
名称 | 类型 | 描述 |
---|---|---|
title | string | 标题,最大长度 128 |
text | string | 消息内容,最大长度 512 |
▶️ 示例
js
http.request('https://api.hamibot.com/v1/devices/设备_id/messages', {
method: 'POST',
contentType: 'application/json',
headers: {
authorization: '你的令牌(hmp 开头)',
},
body: JSON.stringify({ title: '标题', text: '消息内容' }),
});
shell
curl \
-X POST \
-H "Authorization: 你的令牌(hmp 开头)" \
-H "Content-Type: application/json" \
-d '{"title": "标题", "text": "消息内容"}' \
https://api.hamibot.com/v1/devices/设备_id/messages
✅ 响应
204 成功