Build analytics using APIs


We are currently using SonarQube version 6.7. We have a need to build analytics data store to report metrics out of Sonar especially how the projects have performed in the past scans etc. I have built the following API to get the project and its metics

How do I change the API above to:

  • Get metrics information for all projects. I tried putting a comma but it did not work.

  • Add language and project scan date i,e, I need to report on multiple scans for a given project?


Hi Vijay,

You can’t. You’ll need to iterate over the projects of interest.

For that you want api/measures/search_history. For language, you’ll want to request the value of ncloc_language_distribution. Note that this is a DATA format metric, so it returns something like this:

"value": "css=12191;java=244959;js=2150;ts=102716"

and you’ll need to untangle it after retrieval.


Hi Ann,

Thank you for the response.

The API, api/measures/search_history would not return the project name attribute. How do I differentiate the projects in the result set when I iterate the projects I need. Please clarify.


Hi Vijay,

If you’re iterating over the projects of interest, then you should already know which project the current request is for…

Explicitly, if you’re interested in projects A, B, and C, you already know that querying for &component=A,B,C doesn’t work. Instead, you need to do something like (pseudo code):

for (project in A,B,C) {