I've been trying to create a form using JIRA CLOUD APIs to POST data and create Issues using React App, I have came to the conclusion that the only way to accomplish this using OAuth (1.0a) and/or Basic HTTP is to create a custom ExpressJs middleware.
With both authentication methods I'm able to GET data from JIRA, however I've been really struggling to find the right solution to POST data to JIRA.
I tried Atlassian-Connect as well.
Here is what I have so far for POST
app.get('/issue', function(req, res) {
var html = '<form action="/issue" method="post">' +
'summary:' +
'<input type="text" name="summary" placeholder="summary" />' +
'<br>' +
'description:' +
'<input type="text" name="description" placeholder="description" />' +
'<br>' +
'<button type="submit">Submit</button>' +
'</form>';
res.send(html);
});
app.post('/issue', function(req, res){
var consumer = new OAuth(
base_url+"/plugins/servlet/oauth/request-token",
base_url+"/plugins/servlet/oauth/access-token",
"fnkey",
fs.readFileSync('./jira.pem', 'utf8'), //consumer secret, eg. fs.readFileSync('jira.pem', 'utf8')
'1.0',
"http://localhost:3000/jira/callback",
"RSA-SHA1"
);
var summary = req.body.summary;
var description = req.body.description;
// var html = 'summary: ' + summary + '.<br>' + 'description: ' + description + '.<br>' +
// '<a href="/issue">Got it.</a>';
//
// res.send(html);
params = {
"fields": {
"project":
{
"key": "BG"
},
"summary": summary,
"description": description,
"issuetype": {
"name": "Bug"
}
}
}
function callback(error, data, resp) {
console.log(data);
data = JSON.parse(data);
console.log("data,", data, "error,", error);
return res.send(data);
}
consumer.post(base_url+"/rest/api/2/issue",
"access_token", //authtoken
"secret", //oauth secret
params,
"application/json",
callback);
});