JIRA REST API calls fail when using JSESSIONID cookie authentication using urlfetch

I have a Google App Engine Python application that interacts with a JIRA Cloud instance.

To date the application makes urlfetch calls to JIRA using Basic Authentication but as it is now making dozens of separate REST calls both POST and GET I was hoping that using cookie authentication would reduce the latency somewhat.

example Basic-Authentication code that works:

result = urlfetch.fetch(jira_url,
                        "Basic %s" %
				            base64.b64encode("%s:%s" % (username,

and cookie alternative:

result = urlfetch.fetch(jira_url,
                        headers={"X-Atlassian-Token": "no-check",
                                 "Cookie": "JSESSIONID=529…snip…C4C"

I retrieved the JSESSIONID successfully using the instructions but the cookie query will only return "401 - Unauthorized" error while loading this page. errors as if the cookie has expired.

{ "errorMessages" : 
  [ "You do not have the permission to see the specified issue.",
    "Login Required" ],
  "errors" : {}

In case it is relevant, I am recalling the cookie from Memcache as most of the interactions are made from a Task Queue and necessarily a separate thread, but the cookie is generated immediately before the recall.

2 answers

0 votes

Your request looks pretty much correct based on the documentation - https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-cookie-based-authentication.

The only thing that maybe I would recommend is setting your content-type to application/json in your headers as well, as per the urlfetch documentation if you do not specify, then it will default to www-urlform-encoded, which is likely to cause problems? From https://cloud.google.com/appengine/docs/python/outbound-requests:

When sending an HTTP POST request, if a Content-Type header is not set explicitly, the header is set to x-www-form-urlencoded. This is the content type used by web forms.

Hi Jeff,

The node.js example you linked to actually fails due to the same issue when using the cloud instance. Authentication works but the embedded query in the example the attempts to run with the cookie fails with a 401. Would be good to have someone at Atlassian either confirm the issue or provide some guidance.

Looking at the actual responses coming from the Atlassian on demand servers the cookie expiration is january 1st 1970. Not sure if thats the root cause but would make sense the next request would return a 401.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 09, 2018 in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

369 views 6 0
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