How to Extract JIRA issue custom fields data using REST API and Python

How to Extract JIRA issue custom fields data using REST API and Python

Purpose – To extract the JIRA issue custom fields data using REST API’s and Python

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

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

comments user
Unknown

Jira without authentication?

comments user
mjovel

You are thee best, all I was looking without all the glamour… Disregard Sergey Green comment … he does not know what he is doing :- )