I want to know how to get the issues count in sonar based on the rules for a given project through REST API.
Rest api to get issues count based on rules for a project in Sonar
2.8k Views Asked by Aravind At
2
There are 2 best solutions below
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.)
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 atpaging.total