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