How to Extract JIRA issue custom fields data using REST API and Python
Here in this article we will try to extract the JIRA issue custom fields data using REST API’s and Python.
JIRA REST API
I was working on an activity were i wanted to extract the JIRA issue custom fields data using REST API’s and use that data further for other purpose.
JIRA rest api Java Client (JRJC) was one of the option which i could use to extract the custom field data but that would required some dependent jar to made available during the java code building.
Inspite of using such a Heavy method which required downloading of dependent jar file, i opted to use Python which has inbuild json module along with the JIRA rest api’s.
Script
Here is a sample python code which could be used to extract the jira issue data and extract all the custom fields value for particular jira issue.
#!/usr/bin/python
import json
import urllib2
print "Getting the JSON data from the JIRA Issue"
## JRA-123 is an example issue number in JIRA
json_string = urllib2.urlopen('http://<FQDN>/rest/api/latest/issue/JRA-123')
json_data = json.load(json_string)
print json_data
print "Getting the Fields data"
fields = urllib2.urlopen('http://<FQDN>/rest/api/latest/field')
json_fields = json.load(fields)
for i in xrange(1,100 ):
custom=json_fields[i]["custom"]
if a==True:
print json_fields[i]["name"]
id=json_fields[i]["id"]
print json_data["fields"][id]
#endif
#endfor
Hope you enjoyed reading this article. Thank you..
2 COMMENTS