I want to extract data present on sonar dashboard for all projects with API .No APi specified is helpful for me

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • what are you trying to achieve
  • what have you tried so far to achieve this

Using version SonarQube 7.9.5
Wanted to get all project data like code smells,bug,vulnerabilities ,last aalysis date,bug,coverage,duplications,Last analysis date specified in the dashboard for each project.
Did not find an API which returns exactly this .
Could you please help ?

Hi @ammu and welcome to the community :wave:

yeah you can do that via the api but you will need to do multiple calls.
for project data, like code smells and vulnerabilities and stuff you need to call api/measures/component while the last analysis date can be obtained with api/components/show. you can view the documentation for each of these api endpoints directly in SQ when clicking on web_api in the footer of SQ.

for api/measures/component you will need to create a list with fields that you want to get, so something like this:

curl -u username:password http://your.sonarqube.host/api/measures/component?additionalFields=period%2Cmetrics&component=<your component id>&metricKeys=alert_status%2Cquality_gate_details%2Cbugs%2Cnew_bugs%2Creliability_rating%2Cnew_reliability_rating%2Cvulnerabilities%2Cnew_vulnerabilities%2Csecurity_rating%2Cnew_security_rating%2Csecurity_hotspots%2Cnew_security_hotspots%2Csecurity_hotspots_reviewed%2Cnew_security_hotspots_reviewed%2Csecurity_review_rating%2Cnew_security_review_rating%2Ccode_smells%2Cnew_code_smells%2Csqale_rating%2Cnew_maintainability_rating%2Csqale_index%2Cnew_technical_debt%2Ccoverage%2Cnew_coverage%2Clines_to_cover%2Cnew_lines_to_cover%2Ctests%2Cduplicated_lines_density%2Cnew_duplicated_lines_density%2Cduplicated_blocks%2Cncloc%2Cncloc_language_distribution%2Cprojects%2Clines%2Cnew_lines%2Cnew_blocker_violations%2Cnew_critical_violations

while the call to api/components/show is a little more simple:

curl -u username:password http://your.sonarqube.host/api/components/show?component=<your component id>

The SQ frontend fetches all data via API calls to the backend, so when you are not sure how something works the network tab in your browser might be useful too

hope that helps

@Tobias_Trabelsi Thankyou so much .As I am very new to this.What is component id ?
How can we get that ? .If I want any other fields like codesmell,duplications can we add to this ? Will it retrieve for every project present in the dashboard by using the api specified ?

The component ID is the one that is specified when creating a new project in SQ. you can view it in the URL of the dashboard of each project as well, for example with this project in our sonarqube instance: SonarQube the ID would be org.sonarsource.java%3Ajava. you can also view it when you click on project information there.

in my snippet for api/measures/component the fields for codesmell and duplications are already added.

@Tobias_Trabelsi Thankyou so much it worked .

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