List all the issues of a project with JIRA Python

Antoine
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2016

Hello all,

 

All the question is in the title, how to list ALL the issues of a project with JIRA python ?

Actually i've done this code :

def simple_issue(projects):

    i = jira.search_issues('issuetype=Bug', maxResults=None)

    print(i)

But it list only 50 issues or less. It is due to the fact that issues during the search are shown by pages containing each 50 issues and the python package cannot access to the next pages. Do you know how could i do ?

Or then not to reach has the list of issues but to reach has the list of issuetypes present in the config of the project?

6 answers

1 accepted

10 votes
Answer accepted
MattS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2016
block_size = 100
    block_num = 0
    while True:
        start_idx = block_num*block_size
        issues = jira.search_issues(jql, start_idx, block_size)
        if len(issues) == 0:
            # Retrieve issues until there are no more to come
            break
        block_num += 1
        for issue in issues:
            log.info('%s: %s' % (issue.key, issue.fields.summary))
Antoine
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2016

it works, thank you ! 

Like Kawaljeet Singh likes this
Behnam Kasmapour Seighalani September 21, 2017

Hi all,

I tried this code and got an error for name 'jql' 

[SOLVED]

Behnam Kasmapour Seighalani September 21, 2017

Then later on when I'm done with this error I get a new one for 'log'

 [SOLVED]

Alwyn January 18, 2019

Solved how?

Like # people like this
Aamir Jamil March 3, 2020
#NOW SOLVED THANKS :)
while True:

start_idx = block_num * block_size
if block_num == 0:
issues = jira.search_issues(jql, start_idx, block_size)
else:
more_issue = jira.search_issues(jql, start_idx, block_size)
if len(more_issue)>0:
for x in more_issue:
issues.append(x)
else:
break
if len(issues) == 0:
# Retrieve issues until there are no more to come
break
block_num += 1

print(len(issues))

for issue in issues:
print('hi %s: %s' % (issue.key, issue.fields.summary))
1 vote
Matt Ashfield October 3, 2016

Hi,

 

see args of the function...

search_issues(jql_str, startAt=0, maxResults=50, validate_query=True, fields=None, expand=None, json_result=None)

 

use startAt and maxResults looping round incrementing StartAt by maxResults

 

wink

Antoine
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2016

def simple_issue(projects):

    i = jira.search_issues("project=project_name", startAt=0, maxResults=50, validate_query=True, fields=None, expand=None, json_result=None)

print(i)

 

It list 50 issues too ...

Jeff
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 3, 2016

That is because you are still specifying maxResults=50, try changing to maxResults=2000

Marcello Romani October 20, 2017

The server won't return more than a configured number of results at most.

I believe the default is 1000.

Modha K Khammammettu January 26, 2018

Can you please post full python script. I am having issues getting connection 405 error.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 26, 2018

405 has nothing to do with your script, it happens when you are attempting to pass back a file that does not have the necessary permissions on the server to receive Post information from another script.

In other words, your script is asking Jira to do something it does not have permissions to do.  Check what you are asking is correct and the user has the correct permissions

Modha K Khammammettu January 26, 2018

Hello Nic

 

Thanks for response

Here is the script: (I am using Jira 7.4.4 )

import httplib
import urllib
import json

conn = httplib.HTTPConnection("myjira:2002")
args = urllib.urlencode({'username':'myuser', 'password':'mypassword'})
headers = {'accept':'application/json'}
r1 = conn.request("post","/rest/auth/1/session",args, headers)

# --- Authenticate to jira ----------------
r2 = conn.getresponse()
print r1,r2.status,r2.reason,r2

 

Not sure what is wrong?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 26, 2018

Nor do I.  405 means you don't have permission to post.  Are you sure you have the right url, the right user details and that the call you are making is supposed to be a post?  And are you sure python sends it over in the right format?

Modha K Khammammettu January 26, 2018

I am admin on Jira and using same credentials. Is there anyway to find out more info for  debugging.

Url is fine as I use same url for logging from browser.

 

The call I am making is a post as you can see in code

Modha K Khammammettu January 26, 2018

tested using postman and I get 415 error: Unsupported Meda type

 postman_img.JPG

 

Modha K Khammammettu January 26, 2018

used application/json (lower case A as well)

Modha K Khammammettu January 26, 2018

Logs atlassian-jira-security.log shows this:

http-nio-2002-exec-829 myuser 826x10767233x1 86f8ya 1yy.1xx.2xx.xxx /rest/auth/1/session The user 'myuser' has PASSED authentication.

Eric Sebian February 9, 2018

Good morning. Looking at the response:

 i = jira.search_issues("project=project_name", startAt=0, maxResults=50, validate_query=True, fields=None, expand=None, json_result=None)

print(i)

is there a wildcard that I can use for project? Of course I tried "*" but that didn't work. I haven't been able to figure that out. Thanks.

1 vote
Petar Petrov (Appfire)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2016

Have you tried using maxResults=sys.maxint (or sys.maxsize if using Python 3)?

Antoine
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2016

import sys ?

0 votes
blueinc May 16, 2022

Here's another solution to this old question: I found, in the args of the function, this: 

If maxResults evaluates as False, it will try to get all issues in batches.

So, if you just set maxResults=False, it will automagically return all the results. You don't have to guess at a number you 'think' might be higher than the actual number of results or do all of the batching manually.

issues = jira.search_issues(jql_str, maxResults=False)

HTH,

Brian

0 votes
Vivian Young July 15, 2020

This is a really old question but I was wondering the same thing. My solution is slightly different from the ones mentioned above.

To remove the default limit of 50 issues, set the limit to something like this:

jira.jql(jql, limit=1000)

Hope this was helpful.

0 votes
Shiva Prasad Rudrappa Hattaraki November 21, 2019

import jira.client
from jira.client import JIRA


jira_options={'server': 'https://jira.com'}
jira=JIRA(options=jira_options,basic_auth=('admin','password'))

 

issues_in_project = jira.search_issues('JQL',startAt=0, maxResults=2000, validate_query=True, fields=None, expand=None, json_result=None)

print (issues_in_project)

 

This will work for you.

Rushabh Patel April 26, 2020

Hi Shiva,

 

Using your code it is giving just 100, where my expected answer is 455.

Prod Support May 18, 2021

You can set the startAt index to be something else lets say 200 and maxResults to be 300 and it will give issues within that frame. This way you can find others as well and concatenate them. At a time, it gives max 100 issues only. 

Suggest an answer

Log in or Sign up to answer