# API to get current test coverage

**URL:** <https://community.sonarsource.com/t/api-to-get-current-test-coverage/29543>\
**Category:** SonarQube Cloud\
**Created:** [August 13, 2020, 6:45pm UTC](https://community.sonarsource.com/t/api-to-get-current-test-coverage/29543 "2020-08-13T18:45:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lucas\_Lobosque](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/lucas_lobosque/32/8864_2.png) [@Lucas\_Lobosque](https://community.sonarsource.com/u/Lucas_Lobosque)\
**Post date:** [August 13, 2020, 6:45pm UTC](https://community.sonarsource.com/t/api-to-get-current-test-coverage/29543/1 "2020-08-13T18:45:55Z")

</div>

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/](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?

---

<div class="post-metadata">

**Author:** ![Tobias\_Trabelsi](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/tobias_trabelsi/32/31755_2.png) [@Tobias\_Trabelsi](https://community.sonarsource.com/u/Tobias_Trabelsi)\
**Post date:** [August 14, 2020, 8:58am UTC](https://community.sonarsource.com/t/api-to-get-current-test-coverage/29543/2 "2020-08-14T08:58:42Z")

</div>

Hey @Lucas_Lobosque ,

you can authenticate with an API token that you can get from your profile ([https://sonarcloud.io/account/security/](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:

```bash
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](https://docs.sonarqube.org/latest/extend/web-api/#WebAPI-UserToken) but the api documentation is baked in, so there is no additional documentation about it

Hope that helps

---

<div class="post-metadata">

**Author:** ![Lucas\_Lobosque](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/lucas_lobosque/32/8864_2.png) [@Lucas\_Lobosque](https://community.sonarsource.com/u/Lucas_Lobosque)\
**Post date:** [August 14, 2020, 6:31pm UTC](https://community.sonarsource.com/t/api-to-get-current-test-coverage/29543/3 "2020-08-14T18:31:45Z")

</div>

Thanks Tobias, that worked perfectly

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [August 21, 2020, 6:31pm UTC](https://community.sonarsource.com/t/api-to-get-current-test-coverage/29543/4 "2020-08-21T18:31:54Z")

</div>

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