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
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
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
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:
componentKeys
parameterps=1
to minimize the outputThis 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.)