Get fields from a specific Jira issue

Question:

I’m trying to get all the fields and values from a specific issue my code:

authenticated_jira = JIRA(options={'server': self.jira_server}, basic_auth=(self.jira_username, self.jira_password))
issue = authenticated_jira.issue(self.id) 
print issue.fields()

Instead of returning the list of fields it returns:

<jira.resources.PropertyHolder object at 0x108431390>
Asked By: Kobi K

||

Answers:

Found using:

print self.issue_object.raw

which returns the raw json dictionary which can be iterate and manipulate.

Answered By: Kobi K
authenticated_jira = JIRA(options={'server': self.jira_server}, basic_auth=(self.jira_username, self.jira_password))
issue = authenticated_jira.issue(self.id) 

for field_name in issue.raw['fields']:
    print "Field:", field_name, "Value:", issue.raw['fields'][field_name]

Depends on field type, sometimes you get dictionary as a value and then you have to find the actual value you want.

Answered By: ThePavolC

You can use issue.raw['fields']['desired_field'], but this way is kind of indirectly accessing the field values, because what you get in return is not consistent. You get lists of strings, then just strings themselves, and then straight up values that don’t have a key for you to access them with, so you’ll have to iterate, count the location, and then parse to get value which is unreliable.

Best way is to use issue.fields.customfield_# This way you don’t have to do any parsing through the .raw fields
Almost everything has a customfield associated with it. You can pull just issues from REST API to find customfield #’s, or some of the fields that you get from using .raw will have a customfield id that should look like “customfield_11111” and that’s what you’ll use.

Answered By: E. Oregel

Using Answer from @kobi-k but dumping in better format, I used following code:

 with open("fields.txt", "w") as f:
   json.dump(issue.raw, f, indent=4)

It dumped all the fields in a file with name "fields.txt"

Answered By: Vivek Agrawal

You can access to properties via PropertyHolder using dict in the next way:

jira = JIRA(server, basic_auth=(email, token), options={"headers": {"User-Agent": user_agent("my_package", "0.0.1")}})
jp = jira.project(project)

jp.avatarUrls.__dict__['48x48']


Out[20]: 'https://*****.atlassian.net/rest/api/2/universal_avatar/view/type/project/avatar/10414'
Answered By: Han Solo