API to get current test coverage

Hi, I would like to programatically get the current test coverage of one of my projects.
I was able to find the API documentation under this link https://sonarcloud.io/web_api/ but I am not sure how to get that data and how to authenticate.
In fact, I don’t even know what the API url is.
Is there any other source of documentation for the REST API?

Hey @Lucas_Lobosque ,

you can authenticate with an API token that you can get from your profile (https://sonarcloud.io/account/security/), or via http basic auth with username/password.

The API URL that you are looking for is described for each endpoint, so for your specific request it would be something like this:

curl -u $SONARCLOUD_TOKEN: https://sonarcloud.io/api/measures/search_history?from=$DATE&component=$COMPONENT_KEY&metrics=coverage&ps=1000

The $DATE should be in YYYY-MM-DD format and the component key can be extracted from your project.

you can find more information about the authentication in the sonarqube docs but the api documentation is baked in, so there is no additional documentation about it

Hope that helps

Thanks Tobias, that worked perfectly

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