Below is the code snipped to get the tickets belonging to a specific project, final url is working when I directly open it in browser but I am getting status code 400 in my response can some one help.
I am running code like -
node test.js proj_Id severity
----------------------------------------------------------------
const request = require("request");
const jiraurl = "https://xyz.atlassian.net/rest/api/latest/search?jql=";
var auth = new Buffer("abc@cdf.com"+':'+"1234").toString('base64');
var getparams = {
url: jiraurl,
method: 'GET',
header: {
Authorization: 'Basic'+auth,
'Content-Type': 'application/json'
}
};
function getDetails(parameters, callback){
request(parameters, function(err, response, body){
if(!err){
var result="";
console.log(response);
if((parameters.method == "POST" && response.statusCode == 201) || (parameters.method == "GET" && response.statusCode == 200)){
console.log(response);
result = JSON.stringify(JSON.parse(response.body));
}
console.log("All good");
return callback(null, result);
} else {
console.log("Some error");
return callback(err, null);
}
});
};
function getTickets(projId, sev, callback){
getparams.url = jiraurl+"project="+projId+"%20and%20cf[12342]="+sev+"%20and%20assignee!=null";
console.log(getparams.url);
getDetails(getparams, function(err, data)
{
// data= JSON.parse(data);
console.log("Inside callback");
console.log(data);
if(!err)
console.log(data);
else
console.log("Error : "+err);
});
};
getTickets(process.argv[2], process.argv[3]);
Hey Shubham,
Looks like you're generating the basic auth header correctly (email:token -> base64 encoded) per our basic auth instructions. We have however recently starting returning 401's if you use a password rather than an API Token for requests to Atlassian Cloud.
You can have multiple API tokens per account (one for each script/application for example) and revoke them at any time without having to change your password. They're quite useful! Here are the instructions for generating a new API token:
Note:
Replace the password in line 3 of your script with an API token and I think you'll be in business!
Cheers,
Daniel
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.