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
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,721 views 17 21
Read article

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