#node.js #rest #http-status-code-400 #bitbucket-api
#node.js #rest #http-status-code-400 #bitbucket-api
Вопрос:
Я создаю оболочку nodejs вокруг Bitbucket REST API, вот документация для REST API для создания проблемы https://confluence.atlassian.com/display/BITBUCKET/issues Resource#issuesResource-POSTanewissue
Каждый раз, когда я пытаюсь создать проблему, служба возвращает ошибку 400, в которой говорится, что некоторые обязательные поля отсутствуют, ниже приведен мой код
this.createIssue = function(accountName, repoName, title,callback) {
var options = {
rejectUnauthorized: this.strictSSL,
uri: this.makeUri('/repositories/' accountName '/' repoName '/issues'),
method: "POST",
followAllRedirects: true,
json: true,
body:{
title:title,
}
};
console.log(options.body)
this.doRequest(options, function(error, response, body) {
if (error) {
callback(error, null);
return;
}
if (response.statusCode === 404) {
callback('Version does not exist or the currently authenticated user does not have permission to view it');
return;
}
if (response.statusCode === 403) {
callback('The currently authenticated user does not have permission to edit the version');
return;
}
if (response.statusCode !== 200) {
callback(response.statusCode ': Unable to connect to JIRA during createVersion.');
return;
}
callback(null,body)
});
};
Я не уверен, что я делаю не так или что я упускаю?
Ответ №1:
Я действительно нашел проблему, это была кодировка, которая вызывала проблему, как только я установил ее на правильную, она действительно начала работать. Изменил форму параметра «форма» на «тело»
рабочий код
this.createIssue = функция (имя учетной записи, имя ответа, заголовок, обратный вызов) {
var options = {
rejectUnauthorized: this.strictSSL,
uri: this.makeUri('/repositories/' accountName '/' repoName '/issues'),
method: "POST",
followAllRedirects: true,
json: true,
form:{
title:title,
}
};
console.log(options.body)
this.doRequest(options, function(error, response, body) {
if (error) {
callback(error, null);
return;
}
if (response.statusCode === 404) {
callback('Version does not exist or the currently authenticated user does not have permission to view it');
return;
}
if (response.statusCode === 403) {
callback('The currently authenticated user does not have permission to edit the version');
return;
}
if (response.statusCode !== 200) {
callback(response.statusCode ': Unable to connect to JIRA during createVersion.');
return;
}
callback(null,body)
});
};