Get no. of blocker/critical severity code smells from SonarCloud API

I would like to be able to query the following metrics from the SonarCloud web API:

  • number of Code Smells with severity Blocker, and
  • number of Code Smells with severity Critical.

This appears to be unsupported.

I can retrieve values for various metrics, as listed here:

…and it does allow me to query the total number of code smells and the number of new code smells. But it does not provide a standard metric for the things I’m looking for.

I can get actual values (measures) using this API:

…but that does not allow filtering by severity.

Any hints would be appreciated !

Hey there.

While there’s no specific metric for “Blocker Code Smells”, you can use GET api/issues/search to filter for the issues and add facets=severities to get a breakdown by severity.

For example, at the bottom of this API call:

https://sonarcloud.io/api/issues/search?componentKeys=org.sonarsource.iac%3Aiac&types=types&facets=severities

  "facets":[
      {
         "property":"severities",
         "values":[
            {
               "val":"MINOR",
               "count":47
            },
            {
               "val":"MAJOR",
               "count":16
            },
            {
               "val":"CRITICAL",
               "count":5
            },
            {
               "val":"INFO",
               "count":1
            },
            {
               "val":"BLOCKER",
               "count":0
            }
         ]
      }
   ]
}
2 Likes

Awesome, that’s exactly what I was looking for! Thanks, @Colin.

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