1

I am building a NodeJS application from where I want to get project/issues from JIRA using REST APIs provided by JIRA. My jira is running on some server ('http://example.com:8080/secure/Dashboard.jspa') and I am able to use REST APIs from POSTMAN using BASIC AUTH to get all kind of data but when I tried to log in to JIRA using REST APIs and NodeJS, I am getting some response but I am not able to understand it how I am going to use that information to call other APIs.

What I am doing is, I am passing username and password as a command-line args then I am sending those creds to login to JIRA. Then I am going to use the 'node-fetch' package to get information from REST APIs.

Below is my code:

const fetch = require("node-fetch");
const yargs = require("yargs");
var JiraClient = require("jira-connector");
var request = require("request");

const jiraBaseUrl = "http://example.com:8080/secure/Dashboard.jspa";
const loginUrl = "auth/1/session";

const username = yargs.argv.u;
const password = yargs.argv.p;
const projectName = yargs.argv.n;

var headers = {
  "Content-Type": "application/json"
};

var options = {
  url: "http://example.com:8080/rest/api/2/issue/createmeta",
  headers: headers,
  auth: {
    user: username,
    pass: password
  }
};

function callback(error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
  }
}

request(options, callback);

Can somebody please tell me what I am doing wrong or what do I need to do with the data I am getting in order to use other APIs like ('http://example.com:8080/rest/api/2/issue/10008')? Or am I doing something wrong to login?

I have read the documentation on the JIRA website but was not able to understand correctly.

3
  • What is the error that you are getting? Commented Mar 11, 2020 at 18:49
  • @Ayush..I am not getting any specific errot but getting some big data as a JSON response.. Commented Mar 11, 2020 at 20:22
  • Side note: your baseurl would be http://example.com:8080instead. You can find this at example.com:8080/secure/admin/ViewApplicationProperties.jspa Commented Mar 12, 2020 at 13:54

1 Answer 1

2

If you look at the Jira Rest API documentation, rest/api/2/issue/createmeta is the end point for Get create issue metadata. It "returns details of projects, issue types within projects, and, when requested, the create screen fields for each issue type for the user. " This data is supposed to be huge since it returns the details of all projects, and all issue types within projects.

If you want to use other API just change the url to the appropriate url with the correct endpoints (documentation) and follow the documentation on what to send as the body data.

Here is one example of getting the details of one issue: Put the issueIdOrKey you want to get in the brackets

var options = {
   method: 'GET',
   url: 'http://example.com:8080/rest/api/latest/issue/{issueIdOrKey}', 
   auth: { username: username, password: password },
   headers: {
      'Accept': 'application/json'
   }
};

request(options, function (error, response, body) {
   if (error) throw new Error(error);
   console.log(
      'Response: ' + response.statusCode + ' ' + response.statusMessage
   );
   console.log(body); //this would log all the info (in json) of the issue 
   // you can use a online json parser to look at this information in a formatted way

});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.