How to perform the cookie base authentication through groovy in post script function.

i want to cookie base authentication through script post function to call the rest api.

1 answer

Thanks Alexey, but this article is not opening as it says that we are unable to find the page you are looking for.

Alexey Matveev Community Champion Nov 14, 2017

try this one

In short you would need to do the following:

1. Connect to Jira and get the cookie:

curl -X POST \ \
  -H 'content-type: application/json' \
  -d '{ "username": "myuser", "password": "mypassword" }'

It will return it the code like this

   "loginInfo" : {
      "lastFailedLoginTime" : "2013-11-27T09:43:28.839+0000",
      "previousLoginTime" : "2013-12-04T07:54:59.824+0000",
      "loginCount" : 2,
      "failedLoginCount" : 1
   "session" : {
      "name" : "JSESSIONID",
      "value" : "6E3487971234567896704A9EB4AE501F"

2. Use the cookie in the next REST API calls:

Take the value for JSESSIONID and add it to the next REST API call. For example like this

var Client = require('node-rest-client').Client; client = new Client(); // Provide user credentials, which will be used to log in to JIRA. var loginArgs = { data: { "username": "admin", "password": "admin" }, headers: { "Content-Type": "application/json" } };"http://localhost:8090/jira/rest/auth/1/session", loginArgs, function(data, response){ if (response.statusCode == 200) { console.log('succesfully logged in, session:', data.session); var session = data.session; // Get the session information and store it in a cookie in the header var searchArgs = { headers: { // Set the cookie from the session information cookie: + '=' + session.value, "Content-Type": "application/json" }, data: { // Provide additional data for the JIRA search. You can modify the JQL to search for whatever you want. jql: "type=Bug AND status=Closed" } }; // Make the request return the search results, passing the header information including the cookie."http://localhost:8090/jira/rest/api/2/search", searchArgs, function(searchResult, response) { console.log('status code:', response.statusCode); console.log('search result:', searchResult); }); } else { throw "Login failed :("; } });

 That was code for Node.js. In post function you have to change it.  If you have any futher question , then ask

@Alexey Matveev

i do not have the password of the user, if i would have it , i would have gone for the basic authentication, but to overcome this i want to get the cookie(JSESSIONID) so by passing it i could perform the cookie base authentication.

this has become the obstacle for me as i want to create the page in confluence on the script post function and to do this i have to perform the cookie base or oauth authentication but im unable to proceed with this. hoping to see a resolution from you on this problem.

Thanking in anticipation.



Alexey Matveev Community Champion Nov 14, 2017

JSESSIONID received after connection. You can not get it if you are not connected

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

Looking for anyone who made the switch to Data Center

The Jira Marketing team is putting together an ebook on migrating to Data Center. We're looking for pro tips on how you staffed your project team and organized your Proof of Concept. Share yo...

40 views 0 2
Join discussion

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