Fetching recently updated tickets from JIRA board using Python API

I’m working with the JIRA API in Python and I’ve got it to pull tickets from a board. The problem is it’s showing me the 50 newest tickets by creation date. What I really need is to see the 50 most recently updated tickets instead. Here’s what my code looks like right now:

jira_config = {'server': 'https://mycompany.atlassian.net'}
jira_conn = JIRAConnection(config=jira_config, auth=(my_email, api_key))

for ticket in jira_conn.fetch_issues('project = EXAMPLE'):
    ticket_id = ticket.id
    ticket_data = ticket.raw['fields']
    creation_time = ticket_data['created']
    last_update = ticket_data['updated']

How can I change this to sort by the update time instead of creation time? Any help would be great!

I’ve dealt with this exact issue before. The key is to modify your JQL query to sort by the ‘updated’ field. Here’s what worked for me:

jql_query = ‘project = EXAMPLE ORDER BY updated DESC’
issues = jira_conn.search_issues(jql_query, maxResults=50)

This will fetch the 50 most recently updated tickets. The ‘ORDER BY updated DESC’ part is crucial - it sorts the results by update time in descending order.

Remember to adjust the ‘project = EXAMPLE’ part to match your specific project. Also, you might want to add error handling around the API call, as network issues can sometimes cause problems.

Hope this helps solve your problem!

As someone who’s worked extensively with JIRA’s API, I can offer some insights on your issue. The key here is adjusting your JQL query to sort by the ‘updated’ field. Here’s a modified version of your code that should do the trick:

jql_query = 'project = EXAMPLE ORDER BY updated DESC'
issues = jira_conn.search_issues(jql_query, maxResults=50)

for issue in issues:
    issue_id = issue.id
    issue_data = issue.raw['fields']
    creation_time = issue_data['created']
    last_update = issue_data['updated']
    # Process your data here

This approach will fetch the 50 most recently updated tickets. The ‘ORDER BY updated DESC’ is crucial as it sorts the results based on update time in descending order.

One thing to keep in mind: depending on your JIRA instance’s size and complexity, this query might be resource-intensive. If you’re dealing with a large number of issues, you might want to consider implementing pagination or adding more specific filters to your query to improve performance.

Also, don’t forget to handle potential API errors. JIRA’s API can sometimes be finicky, especially with network issues or rate limiting. Adding some basic error handling can save you a lot of headaches down the line.

hey alex, i’ve run into this before. try changing ur query like this:

jql_query = ‘project = EXAMPLE ORDER BY updated DESC’
issues = jira_conn.search_issues(jql_query, maxResults=50)

this’ll get u the 50 most recently updated tickets. the ORDER BY part is key. lemme know if it works!