# Web API

## Documentation <a href="#documentation" id="documentation"></a>

SonarQube provides web API to access its functionalities from applications. The web services composing the web API are documented within SonarQube, by URL. You can also access the [web API documentation](https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations) from the top bar in SonarQube:

![](https://353248219-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl622HnhaCz6xSuy6XTfl%2Fuploads%2Fgit-blob-8203b225ed08667124547dd357202c90704232b2%2F833bff6ec93e7074a1e20c364d7de1e19ac77c0c.png?alt=media)

## Authentication <a href="#authentication" id="authentication"></a>

Administrative web services are secured and require the user to have specific permissions. In order to be authenticated, the user must provide credentials as described below.

### User token <a href="#user-token" id="user-token"></a>

This is the recommended way. Benefits are described on the page [generating-and-using-tokens](https://docs.sonarsource.com/sonarqube-server/10.3/user-guide/user-account/generating-and-using-tokens "mention").

SonarQube supports the bearer authentication scheme:

```css-79elbk
curl --header 'Authorization: Bearer MY_TOKEN' https://sonarqube.com/api/user_tokens/search
```

Alternatively, you can use the basic scheme with an empty password:

```css-79elbk
# note that the colon after the token is required in curl to set an empty password 
curl -u THIS_IS_MY_TOKEN: https://sonarqube.com/api/user_tokens/search
```

### HTTP Basic Access <a href="#http-basic-access" id="http-basic-access"></a>

Login and password are sent via the standard HTTP Basic fields:

```css-79elbk
curl -u MY_LOGIN:MY_PASSWORD https://sonarqube.com/api/user_tokens/search
```

Users who authenticate in the web application through an OAuth provider, for instance, GitHub or Bitbucket, don’t have credentials and can’t use HTTP Basic mode. They must generate and use tokens.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonarsource.com/sonarqube-server/10.3/extension-guide/web-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
