1

我正在围绕 Bitbucket REST API 构建 nodejs 包装器,这里是用于创建问题的 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)


    });
};

我不确定我做错了什么,或者我错过了什么?

4

1 回答 1

0

我实际上发现了问题,是导致问题的编码,一旦我将其设置为正确的,它实际上就开始工作了。将参数形式“form”更改为“body”

工作代码

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,
    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)


});

};

于 2014-06-13T16:07:10.210 回答