Getting data out of Jira using a REST interface and Python

It is a lot easier than I expected. Have fun with it! Example code:

# Author: J. Baten
# Date: 2012-04-10
import urllib, urllib2, cookielib, json
# set up cookiejar for handling URLs
cookiejar = cookielib.CookieJar()
myopener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
# Search using JQL
queryJQL = "updated >= -1d"
IssuesQuery = {"jql" : queryJQL,"startAt" : 0,"maxResults" : 1000 }
queryURL = jira_serverurl + "/rest/api/latest/search"
req = urllib2.Request(queryURL)
req.add_header("Content-type", "application/json")
req.add_header("Accept", "application/json")
fp =
data = json.load(fp)
#print json.dumps(data,sort_keys=True, indent=2)
#print data["issues"]
for k in  data["issues"]:
print k["key"]
#just take the last one for testing
#now how can I get their worklogs?
# /api/2.0.alpha1/issue/{issueKey}
queryURL = jira_serverurl + "/rest/api/latest/issue/" + a
# override for testing purposes
queryURL = jira_serverurl + "/rest/api/latest/issue/ZANDBAK-15"
print queryURL
req = urllib2.Request(queryURL)
#req.add_header("Content-type", "application/json")
req.add_header("Accept", "application/json")
fp2 =
data2 = json.load(fp2)
print json.dumps(data2,sort_keys=True, indent=2)
print "Original estimate :" + str(data2["fields"]["timetracking"]["value"]["timeoriginalestimate"])
print "Current estimate :" + str(data2["fields"]["timetracking"]["value"]["timeestimate"])
# /api/2.0.alpha1/serverInfo

This entry was posted in Geen categorie. Bookmark the permalink.