Number of pages in Rest API response is broken

Must-share information (formatted with Markdown):

  • which versions are you using: SonarQube 9.9.0 LTS
  • how is SonarQube deployed: Helm
  • what are you trying to achieve: Access issues through rest API
  • what have you tried so far to achieve this: N/A

When I search for issues using the rest API the results are paginated, which is fine. However the response to <server>/api/issues/search?rules=cpp%3AS813&branch=master&ps=500 seems to contain the wrong information for total number of pages. It starts with

{
  "total": 53105,
  "p": 1,
  "ps": 500,
  "paging": {
    "pageIndex": 1,
    "pageSize": 500,
    "total": 53105
  }
}

The total number of issues is 53105. The page size is 500, so there should be ceil(106.21) = 107 pages. However the page total is 53105, which is obviously wrong.

Obviously it’s quite trivial to calculate this page limit ourselves, so it’s not tragic. However requesting page 107 with &p=107 yields:

{
  "errors": [
    {
      "msg": "Can return only the first 10000 results. 53500th result asked."
    }
  ]
}

While the 10,000 violation API limit is documented it seems like quite a low limit. Especially looking at enterprise licenses with multi-million lines of code. At the very least the pagination API should then print the actual maximum page number (10,000 / 500), which is 20.

Ideally this limit should be set in the SonarQube settings for the project. Since for some projects 10,000 is a lot, for some projects 10,000 is nothing. Since we deploy SonarQube on our own servers it doesn’t make sense that we are limited here.

Hello @Carl thanks for sharing this.

Regarding the pagination numbers, the total value is not reporting the total number of pages, but the total number of entries matching the filtering parameters.

In the example you posted are being shown both the supported and deprecated paging details for this endpoint.

{
  "total": 53105, <- deprecated since 9.8
  "p": 1, <- deprecated since 9.8
  "ps": 500, <- deprecated since 9.8
  "paging": {
    "pageIndex": 1,
    "pageSize": 500,
    "total": 53105
  }
}

The field total from the paging object has exactly the same meaning as the deprecated total field on the main level of the response. (You can find the details about the deprecation in the changelog of the endpoint).

Regarding the limit of 10,000 issues being returned by the /api/issues/search API we are aware of the limitation, and its being tracked at this Jira.

If all the issues of the instance have to be retrieved the way for bypassing this limit is to use the internal endpoint /api/issues/pull available since SQ v9.5.

1 Like

Thank you. I think maybe the API could be improved here, since for paging you might be interested in how many pages are left. And especially if it says total under paging it’s quite surprising that this isn’t the page total.

I’ll check the internal API, thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.