使用节点js的JIRA REST API出现405错误

时间:2019-04-30 11:45:07

标签: jira-rest-api

我正在尝试使用REST API创建自动JIRA票证,但始终收到405错误。

我在这里使用示例:https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/

此外,当我直接访问帖子URL时,没有出现任何错误,因此我怀疑这是服务器问题。有什么想法吗?

var Client = require('node-rest-client').Client;
client = new Client();
// Provide user credentials, which will be used to log in to Jira.
var loginArgs = {
    data: {
        "username": "user",
        "password": "pass"
    },
    headers: {
        "Content-Type": "application/json"
    }
};
client.post("https://jira.mydomain.com/rest/auth/1/session", loginArgs, function(data, response) {
    if (response.statusCode == 200) {
        //console.log('succesfully logged in, session:', data.session);
        var session = data.session;
        // Get the session information and store it in a cookie in the header
        var args = {
            headers: {
                // Set the cookie from the session information
                cookie: session.name + '=' + session.value,
                "Content-Type": "application/json"
            },
            data: {
                // I copied this from the tutorial
                "fields": {
                    "project": {
                        "key": "REQ"
                    },
                    "summary": "REST ye merry gentlemen.",
                    "description": "Creating of an issue using project keys and issue type names using the REST API",
                    "issuetype": {
                        "name": "Request"
                    }
                }
            }
        };
        // Make the request return the search results, passing the header information including the cookie.
        client.post("https://jira.mydomain.com/rest/api/2/issue/createmeta", args, function(searchResult, response) {
            console.log('status code:', response.statusCode);
            console.log('search result:', searchResult);
        });
    } else {
        throw "Login failed :(";
    }
});

我希望将使用我在字段部分添加的详细信息来创建REQ类型的Jira票证。

1 个答案:

答案 0 :(得分:0)

我相信您使用的是错误的REST API;您当前正在做的是对GET方法进行POST到Get create issue meta,因此,您得到的是405。如果要创建问题,请使用Create issue({{1 }})。