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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

792 views 2 19
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