文章

青龙面板使用api(openapi)接口请求执行任务

1.设置应用权限

在面板菜单系统设置 ——> 应用设置 里创建一个应用,并赋予相应的权限

2.获取访问令牌token /open/auth/token2

本地搭建的就是主机名是:http://locaohost:5700,如果是vps上就是http://your_vps_ip:5700

然后postman访问 http://locaohost:5700/open/auth/token?client_id=your_client_id&clent_secret=your_client_sceret 来获取token

your_client_idyour_client_sceret 换成第一步创建的应用client_idclent_secret

得到如下响应

{
    "code": 200,
    "data": {
        "token": "35c1e0e4-1b66-4ebe-9789-9ba0e21df33f",
        "token_type": "Bearer",
        "expiration": 1723736341
    }
}

3.axios执行调用任务

比如执行订阅任务

订阅任务的url为/open/subscriptions/run?t={{$timestamp}} timestamp 为时间戳

axios({
  url: 'http://localhost:5700/open/subscriptions/run?t=1234567890',
  headers: {
    Authorization: "Bearer 35c1e0e4-1b66-4ebe-9789-9ba0e21df33f"
  },
  method: 'put',
  data: [1], #这个为订阅任务的ID
})

许可协议:  CC BY 4.0