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.

HI team , i have tried using impact severities for HIGH,MEDIUM- i am getting matched results - API and UI but for some cases there it is matching. Not consistent.

for example :
https://sonarcloud.io/api/issues/search?componentKeys=$project-name&types=CODE_SMELL&ps=500&impactSeverities=LOW

$project-name-is replaced with my project above

it is not giving correct value for the project- LOW total is 4 as per API

image

But results for medium are again matching

and for high also matching , why there is a mismatch for high , low , medium code smells from api value and UI( user interface)
NOTE: I have tried impactSeverities and severities both

Hi @henna ,

Please try below Api call
API call:https://sonarcloud.io/api/issues/search?componentKeys=$(projectKey)&branch=$(branch)&types=$issueType&impactSeverities=$severity&ps=500&statuses=OPEN"

impactSeverities : LOW, MEDIUM, HIGH