Sonar cloud API not given the correct values

Hi team,

I have called the sonar cloud API calls to get the bugs and code smells severity list (Low, Medium, and high), but I am not getting the accurate values. Please suggest.

  1. https://sonarcloud.io/api/issues/search?componentKeys=*Projectkey*&branch=*branchname*&types=BUG&severities=MINOR

  2. https://sonarcloud.io/api/issues/search?facets=types,severities&componentKeys=*projectkey*&ps=1&branch=*branchname*&types=BUG&severities=MINOR

Output:

“facets”: [
{
“property”: “severities”,
“values”: [
{
“val”: “MINOR”,
“count”: 36
},
{
“val”: “MAJOR”,
“count”: 18
},
{
“val”: “BLOCKER”,
“count”: 4
},
{
“val”: “INFO”,
“count”: 0
},
{
“val”: “CRITICAL”,
“count”: 0
}

Original values:
image

Thanks,
Nagarjuna

Hey there.

You should use the impactSeverities facet instead of severities, the latter of which is deprecated.

sonarcloud.io/api/issues/search?facets=types,impactSeverities&componentKeys=Projectname&ps=1&branch=Branch name&types=BUG&impactSeverities=LOW

Above API call does not work.

Output:
image

Thanks,
Nagarjuna

Confusingly, but not mistakenly, this is intentional behavior. The value of a facet are not changed by filters to that facet (this is why in the UI you still see the value for other severities when filtered to a specific severity). You should rely on the total returned in the API response.

{“total”:1,“p”:1,“ps”:100,

As per your comments, we did not get accurate values like low, medium, and high from this API call, correct? If yes, please suggest any alternative options to get the severity values through API calls.

You should be getting accurate values (and I believe you are), however, if you filter to a specific impact severity, the impactSeverities facet will still display the count for all impact severities.

I have observed that the single issue has two types of severity Why is it showing?
then does it get the correct value?

These are two separate issues.