Leveraging Sonarqube API's to extract project related information

Hi

I am currently using SonarQube v6.7, I am looking to get the following information using API’s -

  1. List of sonarqube projects
  2. Lines of code per project
  3. Application / Portfolio that the project is associated with?

I tried exploring api/components and api/measures but that wasn’t of much help.
Any suggestions will be much appreciated.

Regards
Naveen

Hi Naveen,

You’ll find below the answer of your questions.

  1. List of sonarqube projects

api/components/search?qualifiers=TRK

  1. Lines of code per project

api/measures/component?component=<PROJECT_KEY>&metricKeys=ncloc

  1. Application / Portfolio that the project is associated with?

This information is not available in this way, you can only get the list of projects from a Portfolio or Application :
api/components/tree?component=<APPLICATION_OR_PORTFOLIO_KEY>&qualifiers=TRK&strategy=children

Regards

2 Likes

Thanks Julien, with the mentioned queries from you, I was able to get the information but in silos, I probably need to write a script in order to get one consolidated report for the above 3 points. Is there a database query that can simply give the above information in a single report?

Regards
Naveen

Naveen,

Running queries against a production database actively serving an application is not a good idea — and the SonarQube database should be treated as a black box: it is not publicly documented and it can change at anytime from version to version without warning.

Our Web APIs however have clear documentation available as well as consistent deprecation strategies when they are altered (a deprecated parameter will, for example, still be available for 2 major versions post-deprecation before being removed). Assuming you want to run your report more than once across multiple versions of SonarQube, this is very important!

I strongly encourage using the Web APIs.

Colin

Okay, point taken Colin.
Thanks for the prompt reply and recommendations.

Hi,

On my side I need to get by API’s these differents values in one of my SonaQube project :

  • Duplications
  • Number of bugs
  • Rate value for the bugs
  • Number of vulnerabilities
  • Rate value for the vulnerabilities
  • Debt value
  • Debt rate

Could you tell me which API I have to use, and with which parameters please ?

Regards