[英]Getting 401 error when using redmine API for a POST request even though I have included the api key
I am trying to make a post request to create a new wiki page using the redmine-api. 我正在尝试使用redmine-api创建一个新的wiki页面。 I am using JavaScript and Axios. 我正在使用JavaScript和Axios。 However I a getting a 401 error(UnAuthorize). 但是我得到401错误(UnAuthorize)。
My goal is to be able to send a word document to my redmine and create a wiki page. 我的目标是能够将单词文档发送到我的redmine并创建一个wiki页面。
I am using the Api key provided and I did enable the rest api feature in my redmine setting 我正在使用提供的Api键,我确实在我的redmine设置中启用了其余的api功能
I have included the api key in the header however it is not working. 我已经在标题中包含了api密钥,但它无法正常工作。
var wordDocument = "./Redmine.docx"
axios.post('<website url>/uploads.json', {
headers: {
'Content-Type': 'application/octet-stream',
'Cache-Control': 'no-store',
'key': '<api-key>'
},
data:wordDocument
})
.then(function (response) {
console.log("succeeed---> ");
console.log (response)
})
.catch(function (error) {
console.log("failed-----> ");
console.log(error.response.headers)
console.log(error.message)
console.log("failed-----> ");
})
I am getting a status: '401 Unauthorized', 我获得了一个状态:'401 Unauthorized',
Try using the other authentication methods mentioned in the docs: 尝试使用文档中提到的其他身份验证方法:
x passed in as a "key" parameter
- passed in as a username with a random password via HTTP Basic authentication
- passed in as a "X-Redmine-API-Key" HTTP header (added in Redmine 1.1.0)
https://www.redmine.org/projects/redmine/wiki/Rest_api#Authentication https://www.redmine.org/projects/redmine/wiki/Rest_api#Authentication
Also ensure that you're using the correct API key. 还要确保使用正确的API密钥。
You can find your API key on your account page ( /my/account ) when logged in, on the right-hand pane of the default layout. 登录后,您可以在默认布局的右侧窗格中的帐户页面(/ my / account)上找到您的API密钥。
Alright I got it working. 好吧我搞定了。 I did "axios({})" instead of "axios.post". 我做了“axios({})”而不是“axios.post”。 I do not know what the different is? 我不知道有什么不同? I thought it was the same. 我以为它是一样的。 Here is my code for anyone who run into this.\\ 这是我遇到的任何人的代码。
var wordDocument = "./Redmine.docx"
axios({
method: 'post',
url: '<redmind_url>/uploads.json',
headers: { 'Content-Type': 'application/octet-stream'},
params: { 'key': '<api key>'},
data: wordDocument
})
.then(function (response) {
console.log("succeeed---> ");
console.log(response.data)
})
.catch(function (error) {
console.log("failed-----> ");
console.log(error.response.statusText, "-->", error.response.status);
console.log(error.response.headers)
console.log(error.message)
console.log("failed-----> ");
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.