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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,796 views 11 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot