Sonar 7.6 rest api issue

SONAR QUBE 7.6 community edition
Trying to fetch data from web API or REST api
Example:
I have used /api/components

Like my server URL for example: http://10.131.228.75:9000/api/components

The result is - unknown URL.

I tried the same in old SONAR 4.0 it works fine.

Is it any changes in SONAR 7.6. Please share the steps using web API in Sonar 7.6 to retrieve any information.

I’m looking for the value of “Tech Debt” of specific project.

Hi,

see http://10.131.228.75:9000/web_api/api/components
for Web api documentation.
There is:
api/components/search
api/components/show
api/components/tree

Regards,
Gilbert

Thanks for replying Gilbert!

I will go through the documentation that you have shared.

I’m a new bee to SONAR web API.

will you please give one example, so that i can follow the same for my other needs.

I will have to Fetch “Tech debt” data from one of the project named “A”.

How do i search and get it in web browser or a file locally?

Basically i’m looking for syntax and one example.
please help.

Hi.

I think you’re looking for this: (SonaQube URL)/api/measures/component?component=(project key)&metricKeys=sqale_index

Example:

https://next.sonarqube.com/sonarqube/api/measures/component?component=org.sonarsource.javascript%3Ajavascript&metricKeys=sqale_index

{
 "component": {
   "id": "5eab015a-1f76-4ba4-bd89-bf547132d673",
   "key": "org.sonarsource.javascript:javascript",
   "name": "SonarJS",
   "description": "SonarQube JavaScript Analyzer",
   "qualifier": "TRK",
   "measures": [
     {
       "metric": "sqale_index",
       "value": "3901",
       "bestValue": false
     }
   ]
 }
}

The "value": "3901" is measured in minutes. You can compare with: https://next.sonarqube.com/sonarqube/dashboard?id=org.sonarsource.javascript%3Ajavascript

3901 minutes = ~65h = ~8 days

Hi,

the Sonarqube Web api documentation has parameters and response examples.
Just try and use Firefox or Chrome to see the JSON response in your browser.
@Scott already mentioned the right api call for your specific question.
Some more details, i.e. with a projectkey = com.foo.bar:Foobar
To see the measures in Sonarqube Web UI, use
https://yoursonarhost/component_measures?id=com.foo.bar%3Foobar

that will show you something like that

Maintainability means technical debt.

To get the same measures via Web api, use [https://sonar/api/measures/component?component=com.foo.bar:Foobar&metricKeys=code_smells,sqale_index,sqale_debt_ratio]

The JSON Respons will look like that

Regards,
Gilbert

Thanks a lot scott !! This is exactly what we are looking for.

But seems the below calculation is wrong.
3901 minutes = ~65h = ~8 days

Isn’t
3901 minutes = ~65h = 2.7 days ???

Will you please clarify if the value retrieved for “sqale_index” is in MINUTES ? or something else ?

Thanks a ton Gilbert. This is exactly what I’m looking for.

8-hour work day :wink:

1 Like

LOL :smiley: . Thanks for clarifying. Never thought about this :wink: