我是 API 新手
我们公司购买了短信面板,我们应该使用jira postfunctions向客户发送短信。 我想用面板 API 发送短信。 我不知道我做错了什么
他们发送了一个像这样的 json 文件:
{"name": "Send",
"event": [
{"listen": "test",
"script": {
"exec": [ "" ],
"type": "text/javascript",
"packages": {}}
}
],
"protocolProfileBehavior": {
"followRedirects": true,
"disableUrlEncoding": false,
"disableCookies": false
},
"request": {
"auth": {
"type": "bearer",
"bearer": [{
"key": "token",
"value": "{{authToken}}",
"type": "string"
}]
},
"method": "POST",
"header": [{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer"
},
{"key": "",
"value": ""}
],
"body": {
"mode": "raw",
"raw": "[\n\t{\n\t\t\"sender\": \"982000xxx\",\n\t\t\"recipient\": \"98xxxx\",\n\t\t\"body\": \"string\",\n\t\t\"customerId\": \"string\"\n\t}\n]",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://www.test.com/panel/send",
"protocol": "https",
"host": [
"www",
"test",
"com"
],
"path": [
"panel",
"send"
]
}
},
"response": []
},
这是我的常规代码。 我收到 401 错误, 但我不知道我做错了什么。 我搜索了很多, 但我没有任何线索
def httpBuilder = new HTTPBuilder("https://www.test.com")
httpBuilder.headers['Content-Type']="application/json"
httpBuilder.headers['Authorization']=( 'Basic '+"Bearer " + "accesstoken")
httpBuilder.request(POST,JSON) {
uri.path="/panel/send"
body= [sender: "XXXXX",recipient :"XXXXX",body:"Test",customerId :"1"]
response.success = { resp, json ->
log.debug 'Successful is ' +resp.status
}
response.failure = { resp, json ->
log.debug 'Reader is '+resp.status
}
}
授权标头具有以下结构
Authorization <scheme> <credentials>
。这里的scheme表示授权的类型,可以取Basic、Bearer或者Digest等值。在您的情况下,授权标头应包含 Bearer <access_token>
,此处不需要 Basic。