Rest Create Issues doesn't Work with Oauth

Pietro Lehmann April 30, 2019

I'm trying to create(post) an Issue with the rest api using oauth as authentication method. But i always get an Error that I'm not authenticated. GETting Issues works perfectly fine even with an Oauth token. The problem must be the authentication, because as soon as i execute my post-request with basic authentication it works.

My Failing Code:

createTestPromise(oauthKey) {
return new Promise((resolve, reject) => {
const options = {
"url": "http://jira.myCompany.ch/rest/api/2/issue",
"json": true,
"headers": {
"Content-Type": "application/json",
// "Authorization": "Bearer " + oauthKey
},
"auth": { "bearer": oauthKey },
"body": this.data
};
request.post(options, (error, response) => {
if (error) {
reject(error);
} else {
resolve(response);
}
});
});
}

 My Working Code: 

async getIssues(team, project, oauthKey) {
return new Promise((resolve, reject) => {
const api = "http://jira.myCompany.ch/rest/api/2/search?jql=";
const jql = "project%20%3D%20" + project + "%20AND%20status%20%3D%20Done%20AND%20\"Test%20erstellen\"%20%3D%20\"%20\"%20and%20";
const testLink = "Test-Link%20is%20EMPTY%20and%20cf[10702]%20=%20" + team;
request.get(api + jql + testLink,
{ auth: { bearer: oauthKey } }, function (error, response) {
if (error) {
reject(error);
} else {
resolve(response);
}
});
});
}

Is my Request just wrong or doesn't Jira Support Oauth in Post Statements?

1 answer

0 votes
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 27, 2019

Suggest an answer

Log in or Sign up to answer