SonarQube Community Edition APIs for pulling Projects and Metrics data

Hello Team,

We are using SonarQube Community Edition - Version 8.9.7 and trying to generate a custom report for all the projects which are running on it.

We have tried to use a couple of APIs but got 401 error while trying APIs from the Postman tool.
For authentication, we have used Admin user token and project keys as well.

Please help us with the correct APIs which we can use to achieve this.

Hi,

The docs should help.

 
Ann

Hello Team,

I am from the same team as Amol Khanorkar.
We are using SonarQube Community Edition - Version 8.9.7 and trying to generate a custom report for all the projects which are running on it.

We have followed the steps mentioned in the documents and we are now able to get some basic response on the Postman Tool.

Our primary purpose is to get the Quality Gates details, the last execution results, and the analysis data.

But we are unable to get the details which we are looking for. We have used Sonar user token and project keys as well.

Please help us with the correct APIs which we can use to achieve this.

Hi,

If you’re primarily interested in the QG status & details, then a webhook may fit the bill without further effort.

If you really want more detail, then you’ll need to pull it with the APIs. And the best way to master the API is to perform the desired action via the UI and eavesdrop to see which calls the UI made to accomplish the action.

 
HTH,
Ann

Hi Ann,

Thanks for sharing the Webhook documentation. We are checking on how we can configure and use webhook for our purpose.

Could you please let us know what is missing in our below API since we are not getting any analysis data in the response.

API which we tried -
https://[sonarhost]/api/project_analyses/search?project=[projectKey]&branch=[branch]&category=QUALITY_GATE

Response we are getting -
{
“paging”: {
“pageIndex”: 1,
“pageSize”: 100,
“total”: 0
},
“analyses”:
}

Hi,

Regarding your API call, it’s difficult to know what’s missing. I would pare this down to basics. Start with just https://[sonarhost]/api/project_analyses/search?project=[projectKey] to get all analyses on the main branch. If that doesn’t work, the project key is wrong. If it does, add in the next parameter & debug it…

 
HTH,
Ann