Web API
SonarQube provides the Web API to access its functionalities from applications.
The web services composing the web API are documented within SonarQube Server. To access the documentation, select the help button from the top bar in SonarQube Server:

Note that the Web API V2 will gradually replace the Web API as endpoints get deprecated and replaced.
Authenticating to the Web API
Administrative web services are secured and require the user to have specific permissions.
To authenticate to the Web API, we recommend that you use the bearer authentication scheme.
If you cannot use the bearer authentication scheme (e.g., with the API endpoint monitoring/metrics), you can use the X-Sonar-Passcode authentication scheme.
Sending an API request
To make a request, you need to find the HTTP method and the right path for the operation that you want to use.
It’s highly recommended to use form data parameters when making POST requests to the Web API. If you use URI query parameters instead then these parameters won’t be securely passed to the endpoint.
Content-Type header
Unless the Sonar Web API endpoint specifications list a specific Content-Type
value, your request should use the following Content-Type
header:
Content-Type: application/x-www-form-urlencoded
This is the default Content-Type
value set by most tools and libraries, such as curl
and Python’s requests
module, but you should check their documentation for proper usage.
Sample API request
If, for example, you want to use the Web API to extract measures, you can make a "GET MEASURES" call to the /api/measures
endpoint to extract measures of a given metric for a given project. In the case of a private project, the user used to create the user-type token has the Browse permission on this project.
For this example, a possible request and response are shown below.
Notes
Code metrics
You can retrieve code metric values and histories by using the /api/measures
``endpoint. The metric keys are listed in the metric tables in Understanding measures and metrics, or you can use the /api/metrics
endpoint to retrieve them.
Related pages
Last updated
Was this helpful?