Advertisement
Guest User

Untitled

a guest
Feb 4th, 2015
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Client = require('node-rest-client').Client;
  2. client = new Client();
  3.  
  4. // let's login
  5. var loginArgs = {
  6.         data: {
  7.                 "username": "admin",
  8.                 "password": "admin"
  9.         },
  10.         headers: {
  11.                 "Content-Type": "application/json"
  12.         }
  13. };
  14.  
  15. client.post("http://localhost:8090/jira/rest/auth/1/session", loginArgs, function(data, response){
  16.         if (response.statusCode == 200) {
  17.                 console.log('succesfully logged in, session:', data.session);
  18.                 var session = data.session;
  19.  
  20.                 // now let's do some request - for example get our session info
  21.                 var searchArgs = {
  22.                         headers: {
  23.                                 cookie: session.name + '=' + session.value, // the session cookie
  24.                                 "Content-Type": "application/json"
  25.                         },
  26.                         data: {
  27.                                 jql: ""
  28.                         }
  29.                 };
  30.                 client.post("http://localhost:8090/jira/rest/api/2/search", searchArgs, function(searchResult, response) {
  31.                         console.log('status code:', response.statusCode);
  32.                         console.log('search result:', searchResult);
  33.                 });
  34.         }
  35.         else {
  36.                 throw "Login failed :<";
  37.         }
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement