jira-node / node-jira-client

A Node.js wrapper for the Jira REST API
https://jira-node.github.io/
MIT License
449 stars 168 forks source link

api 1 call with api 2 configured? #337

Open giancarlo-rt opened 2 years ago

giancarlo-rt commented 2 years ago

Hi I have a very simple call to create a new issue but it has some weird error, wondering if it is easy to spot the issue:

const main = async(messages) {
        for (const message of messages) {
            var payload = JSON.parse(message.body);
            await create(payload);
        }
}

const create = async (issue) => {
    createbody: {
        console.info(`Jira Issue before creation: ${JSON.stringify(issue)}`);

        var jira = new JiraApi({
            'protocol': 'https',
            'host': xxx,
            'username': xxx,
            'password': xxx,
            'apiVersion': '2',
            'strictSSL': true
        });

        var response = await jira.addNewIssue(issue);
        console.info(`Jira Issue Creation Response: ${JSON.stringify(response)}`);    
        return response;
    }
};

Both prints execute and an issue is created:

{
    "id": "95",
    "key": "XX-12",
    "self": "https://xxx/rest/api/2/issue/95"
}

However I then get this unexpected error (I mean, I dont have anymore calls):

ERROR   Invoke Error    
{
    "errorType": "StatusCodeError",
    "errorMessage": "403 - {\"errorMessages\":[\"You currently don't have access to perform this operation.\"],\"errors\":{}}",
    "name": "StatusCodeError",
    "statusCode": 403,
    "message": "403 - {\"errorMessages\":[\"You currently don't have access to perform this operation.\"],\"errors\":{}}",
    "error": {
        "errorMessages": [
            "You currently don't have access to perform this operation."
        ],
        "errors": {}
    },
    "options": {
        "auth": {
            "user": "xxx",
            "pass": "xxx"
        },
        "rejectUnauthorized": true,
        "method": "GET",
        "uri": "https://xxx/rest/agile/1.0/issue/XX-12?fields=&expand=",
        "json": true,
        "simple": true,
        "resolveWithFullResponse": false,
        "transform2xxOnly": false
    },
    "response": {
        "statusCode": 403,
        "body": {
            "errorMessages": [
                "You currently don't have access to perform this operation."
            ],
            "errors": {}
        },
        "headers": {
            "server": "AtlassianProxy/1.19.3.1",
            "cache-control": "no-cache, no-store, no-transform",
            "content-type": "application/json;charset=UTF-8",
            "strict-transport-security": "max-age=315360000; includeSubDomains; preload",
            "date": "Wed, 02 Feb 2022 15:05:53",
            "atl-traceid": "809be9619e212439",
            "x-arequestid": "29c46a96-790d-48d8-b00d-9ec229778236",
            "x-aaccountid": "62c09fe77c6f980071808b53",
            "x-xss-protection": "1; mode=block",
            "transfer-encoding": "chunked",
            "timing-allow-origin": "*",
            "x-envoy-upstream-service-time": "35",
            "x-content-type-options": "nosniff",
            "connection": "close",
            "set-cookie": [
                "atlassian.xsrf.token=61e647e1-4926-4827-a4f2-ad5b09381a83_31c41139ca04fceaca21f2701a341436d7815c09_lin; path=/; SameSite=None; Secure"
            ],
            "expect-ct": "report-uri=\"https://web-security-reports.services.atlassian.com/expect-ct-report/global-proxy\", enforce, max-age=86400"
        },
        "request": {
            "uri": {
                "protocol": "https:",
                "slashes": true,
                "auth": null,
                "host": "xxx",
                "port": 443,
                "hostname": "xxx",
                "hash": null,
                "search": "?fields=&expand=",
                "query": "fields=&expand=",
                "pathname": "/rest/agile/1.0/issue/XX-12",
                "path": "/rest/agile/1.0/issue/XX-12?fields=&expand=",
                "href": "https://xxx/rest/agile/1.0/issue/XX-12?fields=&expand="
            },
            "method": "GET",
            "headers": {
                "authorization": "xxx",
                "accept": "application/json"
            }
        }
    },
    "stack": [
        "StatusCodeError: 403 - {\"errorMessages\":[\"You currently don't have access to perform this operation.\"],\"errors\":{}}",
        "    at new StatusCodeError (/opt/request-promise-core/lib/errors.js:32:15)",
        "    at Request.plumbing.callback (/opt/request-promise-core/lib/plumbing.js:104:33)",
        "    at Request.RP$callback [as _callback] (/opt/request-promise-core/lib/plumbing.js:46:31)",
        "    at Request.self.callback (/opt/request/request.js:185:22)",
        "    at Request.emit (events.js:314:20)",
        "    at Request.EventEmitter.emit (domain.js:483:12)",
        "    at Request.<anonymous> (/opt/request/request.js:1154:10)",
        "    at Request.emit (events.js:314:20)",
        "    at Request.EventEmitter.emit (domain.js:483:12)",
        "    at IncomingMessage.<anonymous> (/opt/request/request.js:1076:12)",
        "    at Object.onceWrapper (events.js:420:28)",
        "    at IncomingMessage.emit (events.js:326:22)",
        "    at IncomingMessage.EventEmitter.emit (domain.js:483:12)",
        "    at endReadableNT (_stream_readable.js:1241:12)",
        "    at processTicksAndRejections (internal/process/task_queues.js:84:21)"
    ]
}

version is 6.23.0

kentora commented 2 years ago

It seems you try to read the issue somewhere else (using the agile api) and do not have permission to do so. I haven't looked into the agile api, so I'm not sure if you're doing it right or not, but I'm pretty confident it is not happening in the provided code

giancarlo-rt commented 2 years ago

No, the single addNewIssue is being called and nothing else, if you read the library code, agile can get called rather than rest, which I find weird because I explicitly call to use api version 2, so agile v1 sounds like it would be out of bounds