Get fields from a specific Jira issue
Asked Answered
A

5

17

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>
Admass answered 3/6, 2015 at 9:19 Comment(0)
A
14

Found using:

print self.issue_object.raw

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

Admass answered 3/6, 2015 at 9:44 Comment(0)
V
39
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.

Vuillard answered 3/6, 2015 at 9:58 Comment(1)
Yep, just like i've answered the raw solve the issue.Admass
A
14

Found using:

print self.issue_object.raw

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

Admass answered 3/6, 2015 at 9:44 Comment(0)
G
5

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.

Georginageorgine answered 15/6, 2017 at 23:53 Comment(0)
H
0

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"

Haldeman answered 4/11, 2022 at 8:18 Comment(0)
G
0

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'
Gwendagwendolen answered 1/4, 2023 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.