6

I am trying to fetch all issues related to a project. When I execute the below code, I get only 50 results. I need to navigate all pages and get all the bugs.Please help

all_issues = jira.search_issues('project=ProjectName')
    each_issue = sorted([issue.key for issue in all_issues])
    for item in each_issue:
        print item

This gives me only 50 issues since the page has default value of 50. I need to get all the issues.

Rakesh Nittur
  • 445
  • 1
  • 7
  • 20

2 Answers2

9

-- Update 18/Oct/2021

As discovered in the answer below, setting maxResults to False appears to remove the limit on the result set.

all_issues = jira.search_issues('project=ProjectName', maxResults=False)

-- Original Post

Try;

all_issues = jira.search_issues('project=ProjectName', maxResults=50, startAt=50)

The results from the REST API are paged, with the default number of results being 50. You can supply the startAt value to start the results from a point in the result set. By default this value is 0.

So, your original query would get results 0-49, the query above would get results 50-99 and changing startAt to 100 would get 100-149, and so on.

You can also increase the value of maxResults to return more results per page. However, this is limited to the max value of jira.search.views.default.max configured in your JIRA instance (set to 1000 by default).

It is not possible to make the API return all issues without paging. You would have to configure jira.search.views.default.max to a very large value and supply that value as maxResults.

André Düwel
  • 532
  • 4
  • 8
JamieB
  • 1,722
  • 18
  • 21
  • Thanks a lot! It works awesome. As you said it limits the value to 1000. I tried setting the value for 'jira.search.views.default.max'. But I get an error 'AttributeError: 'JIRA' object has no attribute 'search''. I want to fetch about 10000 issues. Is there a way? – Rakesh Nittur Nov 20 '15 at 20:04
  • Where are you setting jira.search.views.default.max? This is a JIRA global configuration, it needs to be set in jira-config.properties for the JIRA installation. – JamieB Nov 27 '15 at 14:47
  • @rakesh: is there any way to paginate it easily? Can i predict how many items could be returned in total? – Lormitto May 04 '17 at 16:02
  • @Lormitto I guess number of items returned depends on the value that you set for `maxResults`. – Rakesh Nittur May 04 '17 at 19:53
  • This answer is not correct, since you will always do a new request when you change the startAt. If you e.g. process issues in a way that they won't appear in the search afterwards you will skip some issues – André Düwel Oct 12 '21 at 13:12
  • @AndréDüwel I think stating "it is incorrect" is a bit far; it is a "limitation" that needs to be considered for sure; but with the unfortunate max limit imposed in the search, there isn't another way, unless perhaps you can provide your wisdom? – JamieB Oct 15 '21 at 15:35
  • @JamieB sorry for not directly posting the solution, I found your answer and used it since I just had to accomplish one small task and during that I realized that "limitation". Sorry if you felt offended, that wasn't my intention. I just wanted to share my finding. And I assumed that there will be a better way, since the returned object contains a boolean property: `isLast` After taking the time to look up the source code I found the solution an posted as here as an alternative answer https://stackoverflow.com/a/69608446/4248497 . Hoping it will help other people in the future. :) – André Düwel Oct 17 '21 at 20:49
2

According to the source code: https://github.com/pycontribs/jira/blob/f5d7dd032e719fe35f5fc377f302200f6c69afd4/jira/client.py#L2737

Setting maxResults=False should do the trick, so your example would look like:

all_issues = jira.search_issues('project=ProjectName', maxResults=False)
    each_issue = sorted([issue.key for issue in all_issues])
    for item in each_issue:
        print item

I shortly tested it right now and it worked here.

André Düwel
  • 532
  • 4
  • 8