开发脚本
替换
id 和令牌需要替换为自己的 获取令牌
获取脚本列表
GET /v1/devscripts
▶️ 示例
js
var res = http.request('https://api.hamibot.com/v1/devscripts', {
method: 'GET',
headers: {
authorization: '你的令牌(hmp 开头)',
},
});
log(res.body.json());
shell
curl -H "Authorization: 你的令牌(hmp 开头)" \
https://api.hamibot.com/v1/devscripts
✅ 响应
200 成功
json
{
"count": 1,
"items": [
{
"_id": "bfe67d643ababe0ab6fda054",
"name": "演示脚本"
}
]
}
获取脚本
GET /v1/devscripts/开发脚本_id
▶️ 示例
js
var res = http.request('https://api.hamibot.com/v1/devscripts/开发脚本_id', {
method: 'GET',
headers: {
authorization: '你的令牌(hmp 开头)',
},
});
log(res.body.json());
shell
curl -H "Authorization: 你的令牌(hmp 开头)" \
https://api.hamibot.com/v1/devscripts/开发脚本_id
✅ 响应
200 成功
json
{
"_id": "bfe67d643ababe0ab6fda054",
"name": "演示脚本"
}
运行脚本
POST /v1/devscripts/开发脚本_id/run
参数
名称 | 类型 | 描述 |
---|---|---|
devices | array | 要执行脚本的设备 |
vars | object | 可选,脚本配置 |
▶️ 示例
js
http.request('https://api.hamibot.com/v1/devscripts/开发脚本_id/run', {
method: 'POST',
contentType: 'application/json',
headers: {
authorization: '你的令牌(hmp 开头)',
},
body: JSON.stringify({
devices: [{ _id: 'a51d237e9af41ecc021c9ff6', name: '零号机' }],
}),
});
shell
curl \
-X POST \
-H "Authorization: 你的令牌(hmp 开头)" \
-H "Content-Type: application/json" \
-d '{"devices": [{"_id": "a51d237e9af41ecc021c9ff6", "name": "零号机"}]}' \
https://api.hamibot.com/v1/devscripts/开发脚本_id/run
✅ 响应
204 成功
422 参数错误
停止脚本
DELETE /v1/devscripts/开发脚本_id/run
▶️ 示例
js
http.request('https://api.hamibot.com/v1/devscripts/开发脚本_id/run', {
method: 'DELETE',
contentType: 'application/json',
headers: {
authorization: '你的令牌(hmp 开头)',
},
body: JSON.stringify({
devices: [{ _id: 'a51d237e9af41ecc021c9ff6', name: '零号机' }],
}),
});
shell
curl \
-X DELETE \
-H "Authorization: 你的令牌(hmp 开头)" \
-H "Content-Type: application/json" \
-d '{"devices": [{"_id": "a51d237e9af41ecc021c9ff6", "name": "零号机"}]}' \
https://api.hamibot.com/v1/devscripts/开发脚本_id/run
✅ 响应
204 成功
创建脚本
POST /v1/devscripts
▶️ 示例
js
var res = http.request('https://api.hamibot.com/v1/devscripts', {
method: 'POST',
headers: {
authorization: '你的令牌(hmp 开头)',
},
body: JSON.stringify({ name: '脚本名字' }),
});
log(res.body.json());
shell
curl \
-X POST \
-H "Authorization: 你的令牌(hmp 开头)" \
-d '{"name": "脚本名字"}' \
https://api.hamibot.com/v1/devscripts
✅ 响应
201 成功
json
{
"_id": "bfe67d643ababe0116fda052",
"name": "未命名9527"
}
删除脚本
DELETE /v1/devscripts/开发脚本_id
▶️ 示例
js
var res = http.request('https://api.hamibot.com/v1/devscripts/开发脚本_id', {
method: 'DELETE',
headers: {
authorization: '你的令牌(hmp 开头)',
},
});
shell
curl \
-X DELETE \
-H "Authorization: 你的令牌(hmp 开头)" \
-H "Content-Type: application/json" \
https://api.hamibot.com/v1/devscripts/开发脚本_id
✅ 响应
204 成功
修改脚本
PUT /v1/devscripts/开发脚本_id/files
注意
- 脚本和配置可同时上传,也可单独上传(最多可同时上传 2 个文件)
- 文件大小不能超过 3Mb(以系统为准)
- 配置文件是 JSON 数组,参见 配置脚本
- 需要正确提供 MIME type,脚本
application/javascript
,配置application/json
▶️ 示例
shell
curl \
-X PUT \
-H "Authorization: 你的令牌(hmp 开头)" \
-F "data=@index.js;type=application/javascript" \
-F "data=@config.json;type=application/json" \
https://api.hamibot.com/v1/devscripts/bfe67d643ababe0ab6fda054/files
✅ 响应
204 成功
发布脚本
POST /v1/devscripts/开发脚本_id/publish
注意
仅支持已审核通过的脚本
▶️ 示例
js
var res = http.request(
'https://api.hamibot.com/v1/devscripts/开发脚本_id/publish',
{
method: 'POST',
headers: {
authorization: '你的令牌(hmp 开头)',
},
}
);
log(res.body.json());
shell
curl \
-X POST \
-H "Authorization: 你的令牌(hmp 开头)" \
https://api.hamibot.com/v1/devscripts/开发脚本_id/publish
✅ 响应
201 成功
撤销发布
DELETE /v1/devscripts/开发脚本_id/publish
▶️ 示例
js
var res = http.request(
'https://api.hamibot.com/v1/devscripts/开发脚本_id/publish',
{
method: 'DELETE',
headers: {
authorization: '你的令牌(hmp 开头)',
},
}
);
shell
curl \
-X DELETE \
-H "Authorization: 你的令牌(hmp 开头)" \
-H "Content-Type: application/json" \
https://api.hamibot.com/v1/devscripts/开发脚本_id/publish
✅ 响应
204 成功
创建优惠码
POST /v1/devscripts/开发脚本_id/promocode
注意
仅支持已审核通过且含有付费定价计划的脚本
参数
名称 | 类型 | 描述 |
---|---|---|
percentOff | number | 优惠百分比,范围 1-100,例如 100 为 100% 折扣,相当于免费 |
优惠码有效期 7 天,用于月付,暂不支持其他自定义
▶️ 示例
js
var res = http.request(
'https://api.hamibot.com/v1/devscripts/开发脚本_id/promocode',
{
method: 'POST',
headers: {
authorization: '你的令牌(hmp 开头)',
},
body: JSON.stringify({
percentOff: 20,
}),
}
);
log(res.body.json());
shell
curl \
-X POST \
-H "Authorization: 你的令牌(hmp 开头)" \
-H "Content-Type: application/json" \
-d '{"percentOff": 20}' \
https://api.hamibot.com/v1/devscripts/开发脚本_id/promocode
✅ 响应
201 成功
json
{
"code": "XXXXXXXX", // 优惠码
"percentOff": 20,
"expiresAt": "2023-01-10 23:59:59", // 优惠码有效期
"name": "脚本名称",
"url": "https://hamibot.com/marketplace/xxx" // 脚本链接
}