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,
                        deadline=60,
                        headers={"Authorization": 
                        "Basic %s" %
				            base64.b64encode("%s:%s" % (username,
                                                        password))
                        })

and cookie alternative:

result = urlfetch.fetch(jira_url,
                        deadline=60,
                        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 vote

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published 8 hours ago in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

277 views 4 4
Read article

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