1

I want to know how to get the issues count in sonar based on the rules for a given project through REST API.

Thanks, Aravind

Aravind
  • 53
  • 1
  • 8

2 Answers2

1

In the footer of each page of the SonarQube UI you'll find a link to the API docs for your version. Take a look at issues/search, which you can qualify by componentKeys (project id). In the response JSON (you can see an example in the on-board docs) look at paging.total

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
0

The REST API endpoint that can answer such queries is api/issues/search.

For example given the $KEY of a project, you can find the number of issues using curl and the jq tool like this:

curl "yourserver/api/issues/search?componentKeys=$KEY&ps=1" | jq .total

That is:

  • Set the project key in the componentKeys parameter
  • Use the minimum page size with ps=1 to minimize the output

This will return one issue, thanks to ps=1, but in the JSON response you should see the total field, which contains the total number of issues.

The jq tool will give you a clean output of a single number, if you don't have it, you can simple get the head of the response instead, the value should be easily visible near the top, for example:

$ curl "yourserver/api/issues/search?componentKeys=$KEY&ps=1" | jq .total
{
  "total": 12,
  "p": 1,
  "ps": 1,
  "paging": {
    "pageIndex": 1,
    "pageSize": 1,
    "total": 12
  },
  "issues": [

(In this example there are 12 issues in the project.)

janos
  • 120,954
  • 29
  • 226
  • 236