JIRA CLOUD API - OAuth (1.0a) && Basic HTTP - POST Method

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);
});

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

59 views 0 1
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you