Skip to content

脚本

替换

id 和令牌需要替换为自己的 获取令牌

获取脚本列表

GET /v1/scripts

▶️ 示例

js
var res = http.request('https://api.hamibot.com/v1/scripts', {
  method: 'GET',
  headers: {
    authorization: '你的令牌(hmp 开头)',
  },
});
log(res.body.json());
shell
curl -H "Authorization: 你的令牌(hmp 开头)" \
    https://api.hamibot.com/v1/scripts

✅ 响应

200 成功

json
{
  "count": 1,
  "items": [
    {
      "_id": "bfe67d643ababe0ab6fda054",
      "slug": "FLZoI",
      "name": "演示脚本",
      "version": "1.1.3"
    }
  ]
}

获取脚本

GET /v1/scripts/脚本_id

▶️ 示例

js
var res = http.request('https://api.hamibot.com/v1/scripts/脚本_id', {
  method: 'GET',
  headers: {
    authorization: '你的令牌(hmp 开头)',
  },
});
log(res.body.json());
shell
curl -H "Authorization: 你的令牌(hmp 开头)" \
    https://api.hamibot.com/v1/scripts/脚本_id

✅ 响应

200 成功

json
{
  "_id": "bfe67d643ababe0ab6fda054",
  "slug": "FLZoI",
  "name": "演示脚本",
  "version": "1.1.3"
}

运行脚本

POST /v1/scripts/脚本_id/run

参数

名称类型描述
devicesarray要执行脚本的设备
varsobject可选,脚本配置

▶️ 示例

js
http.request('https://api.hamibot.com/v1/scripts/脚本_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/scripts/脚本_id/run

✅ 响应

204 成功

422 参数错误

停止脚本

DELETE /v1/scripts/脚本_id/run

▶️ 示例

js
http.request('https://api.hamibot.com/v1/scripts/脚本_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/scripts/脚本_id/run

✅ 响应

204 成功

删除脚本

DELETE /v1/scripts/脚本_id

▶️ 示例

js
var res = http.request('https://api.hamibot.com/v1/scripts/脚本_id', {
  method: 'DELETE',
  headers: {
    authorization: '你的令牌(hmp 开头)',
  },
});
shell
curl \
    -X DELETE \
    -H "Authorization: 你的令牌(hmp 开头)" \
    https://api.hamibot.com/v1/scripts/脚本_id

✅ 响应

204 成功