3

New to Sails, i 'am wondering how can i get access to my Jira account via Sails in order to create/edit/search some Issues with the Jira API REST.

I searched for this evrywhere, can someone help me please ?

Here is an exemple of what i want to do :

    module.exports = {

test: function(req, res)

  var https = require('https');
      var https = require('https'), options = {
        host : "jira.company.com",
        port : 80,
        path : "/rest/api/2/search?jql=issue=TASC-1",
        method : 'GET'};
  https.request(options, function(response) {
    var responseData = '';
    response.setEncoding('utf8');

response.on('data', function(chunk){
  responseData += chunk;
});

response.once('error', function(err){
  // Some error handling here, e.g.:
  res.serverError(err);
});

response.on('end', function(){
  try {


       // response available as `responseData` in `yourview`
    res.locals.requestData = JSON.parse(responseData);
  } catch (e) {
  sails.log.warn('Could not parse response from options.hostname: ' + e);
  }
  res.view('client');
}); }).end();}} 

But i got nothing in my View, i think it's normal because i did not authenticate.

2 Answers 2

1

You can use /rest/auth/1/session to authenticate and get cookies: https://docs.atlassian.com/jira/REST/latest/#d2e4234

or you can pass http basic auth headers with your /rest/api/2/search request.

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

Comments

1

it was an authentication problem, to resolve that,I simply add in the request header the login and password properties formatted as the official documentation explained it, so my code becomes:

module.exports = {

test: function(req, res)

  var https = require('https');
      var https = require('https'), options = {
        host : "jira.company.com",
        port : 443,
        path : "/rest/api/2/search?jql=issue=TASC-1",
        method : 'GET'
        headers: {
                 "Authorization": "Basic YWxbG9wMS4zp0bWFuzeThYS5l1TIqaXoxOTg5554Jh"
    }
           };
  https.request(options, function(response) {
    var responseData = '';
    response.setEncoding('utf8');

response.on('data', function(chunk){
  responseData += chunk;
});

response.once('error', function(err){
  // Some error handling here, e.g.:
  res.serverError(err);
});

response.on('end', function(){
  try {

       // response available as `responseData` in `yourview`
    res.locals.requestData = JSON.parse(responseData);
  } catch (e) {
  sails.log.warn('Could not parse response from options.hostname: ' + e);
  }
  res.view('client');
}); }).end();}} 

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.