I’m working on a Python script that pulls ticket information from Jira using a saved filter. Right now my code only displays the ticket key, but I need to also show the summary and status fields for each ticket.
I want all three pieces of information (key, summary, status) to display together on the same line for each ticket. Can someone help me modify my code to access these additional fields?
Here’s what I have so far:
# -*- coding: utf-8 -*-
from jira import JIRA
server_options = {'server': 'https://company-jira.example.com/'}
jira_client = JIRA(server_options, basic_auth=('username', 'password'))
for ticket in jira_client.search_issues('filter=12345', maxResults=100):
print(ticket)
Any guidance would be appreciated!
Had this exact problem when I first started with JIRA’s Python library. The ticket object has way more data than what shows up when you print it - you need to dig into the fields attribute to get what you want. Different field types work differently too.
Here’s how to fix your loop:
for ticket in jira_client.search_issues('filter=12345', maxResults=100):
key = ticket.key
summary = ticket.fields.summary
status = ticket.fields.status.name
print(f"{key} | {summary} | {status}")
Watch out - some fields might be None or empty, so add error handling if your data’s messy. Status is actually a complex object with multiple properties, that’s why you need the .name part to get readable text.
totally agree, using .fields is super important! just like you said, changing your print to print(f"{ticket.key}: {ticket.fields.summary} [{ticket.fields.status.name}]") should def solve your issue. happy coding!
You need to use the fields attribute from the ticket object. When you pull tickets from the JIRA API, all the main details are stored in the fields property. Here’s how to fix your print statement:
for ticket in jira_client.search_issues('filter=12345', maxResults=100):
summary = ticket.fields.summary
status = ticket.fields.status.name
print(f"{ticket.key} - {summary} - {status}")
Just remember that status is an object, so you’ll need to grab the name property to get the actual status text. This’ll give you the key, summary, and status all on one line.