SonarQube API Guide: curl Calls, Deprecations, Java Client

Updated

sonarqube api

Every SonarQube Web API call is a plain HTTP request with a token. Two calls that worked unauthenticated against SonarQube Cloud on 15 October 2026, on the public project SonarSource_sonarqube-scan-action:

$ B=https://sonarcloud.io
$ K=SonarSource_sonarqube-scan-action

$ curl -s "$B/api/measures/component?component=$K&metricKeys=ncloc,bugs,coverage" | jq -c .component
{"id":"AZ1sHZl_D2-gFGkFqVHI","key":"SonarSource_sonarqube-scan-action","name":"sonarqube-scan-action","qualifier":"TRK","measures":[{"metric":"bugs","value":"0","bestValue":true},{"metric":"ncloc","value":"710"}]}

$ curl -s "$B/api/qualitygates/project_status?projectKey=$K" | jq -r .projectStatus.status
OK

That project reports no coverage measure, so the response omits it. The second call belongs to the api/qualitygates family; SonarQube Cloud marks 15 of its 16 actions deprecated since 16 September 2025 (details below). It still answered on 15 October 2026.

On your own server, add the token. Since SonarQube 10.0 the bearer form works and is the one to use; the older HTTP Basic form (token as username, empty password) still works and is what you need against pre-10.0 servers:

curl -s -H "Authorization: Bearer $SONAR_TOKEN" "$SONAR_HOST/api/projects/search"
curl -s -u "$SONAR_TOKEN:" "$SONAR_HOST/api/projects/search"      # older servers

Use https://. A token in an Authorization header over port 80 is a credential handed to every device between you and the server, and it grants whatever the token’s owner can do.

Find out what your server actually exposes — do not guess

Every SonarQube instance publishes its own API surface, including deprecations, at api/webservices/list. This is the single most useful call in the whole API and no tutorial mentions it:

curl -s "$SONAR_HOST/api/webservices/list" \
  | jq -r '.webServices[] | .path as $p | .actions[]
           | select(.deprecatedSince != null) | "\($p)/\(.key)  since=\(.deprecatedSince)"'

Reading that deprecation list on both SonarSource instances produced a result worth knowing. On SonarQube Cloud (read on 23 October 2026) the api/qualitygates family is deprecated: 15 of its 16 actions carry a deprecation date of 16 September 2025, namely project_status, list, select, create_condition and the rest; only unset_default is dated differently, deprecated since 7.0. Cloud reported 31 deprecated actions across 33 web services. On the SonarQube Server instance (read in August 2026) those same actions carry no deprecation at all, and Server reported 29 across 42. If you write one client for both, the deprecation set is not shared. SonarSource’s public SonarQube Server instance (next.sonarqube.com), which those August 2026 measurements used, redirected to SonarSource’s Cloud product page when I checked on 15 October 2026. The script sonarqube-api-guide.sh repeats the two Cloud calls above, re-reads Cloud’s deprecation list and fails if the api/qualitygates family or the project_status date changes, and compiles and runs the Java examples below against the newest sonar-ws on Maven Central. It skips its Server checks, with a dated message, when next.sonarqube.com does not answer, and it removes its scratch directory when it exits.

The Server list also shows api/users/* and api/user_groups/* deprecated since 10.4, superseded by v2 endpoints. SonarQube Server publishes an OpenAPI document for those at api/v2/api-docs — 168 paths on the instance I queried, including /users-management/users and /authorizations/groups. SonarQube Cloud returned 404 for api/v2/api-docs, so v2 discovery was Server-only in August 2026.

The Java examples, compiled

I put two calls in a file — searchProjects() with no arguments and projectStatus("KEY") with a plain string — and ran javac against sonar-ws 26.8.0.126808, the newest version on Maven Central (published 2026-08-05):

OldSnippet.java:8: error: method searchProjects in class ComponentsService cannot be applied to given types;
    Components.SearchProjectsWsResponse r = w.components().searchProjects();
                                                          ^
  required: SearchProjectsRequest
  found:    no arguments
OldSnippet.java:9: error: incompatible types: String cannot be converted to ProjectStatusRequest
    Qualitygates.ProjectStatusResponse q = w.qualitygates().projectStatus("KEY");
2 errors

Every service method takes a request object. This version compiled and ran against next.sonarqube.com in August 2026:

HttpConnector.Builder b = HttpConnector.newBuilder().url(url);
if (token != null) b.token(token);
WsClient ws = WsClientFactories.getDefault().newClient(b.build());

Measures.ComponentWsResponse m = ws.measures().component(
    new ComponentRequest().setComponent(key)
        .setMetricKeys(List.of("ncloc", "coverage", "software_quality_security_rating")));
for (Measures.Measure x : m.getComponent().getMeasuresList())
    System.out.println(x.getMetric() + " = " + x.getValue());

Qualitygates.ProjectStatusResponse q = ws.qualitygates().projectStatus(
    new ProjectStatusRequest().setProjectKey(key));
System.out.println("quality gate = " + q.getProjectStatus().getStatus());
coverage = 95.1
software_quality_security_rating = 1.0
ncloc = 944
quality gate = ERROR

On 15 October 2026 I compiled the same client against sonar-ws 26.10.0.133078, the newest on Maven Central, and ran it against SonarQube Cloud on SonarSource_sonarqube-scan-action. Cloud answers 404 for software_quality_security_rating, a Server metric key, so the metric list became ncloc, bugs and coverage; the rest of the code is unchanged:

bugs = 0
ncloc = 710
quality gate = OK

One thing no tutorial warns about: sonar-ws is not self-contained. Running it needs okhttp, its logging-interceptor, okio, kotlin-stdlib, gson, slf4j-api and an slf4j binding, and protobuf-java at least as new as the gencode version. With protobuf-java 4.32.1 the client died with ProtobufRuntimeVersionException: gencode 4.35.0, runtime 4.32.1; 4.35.0 fixed it. The 26.10.0.133078 release was generated with protobuf 4.36.2: with protobuf-java 4.35.0 it failed with ProtobufRuntimeVersionException: gencode 4.36.2, runtime 4.35.0, and the run above used protobuf-java 4.36.2, the version listed in the sonar-ws pom, together with okhttp 5.5.0. Maven resolves all of this for you — which is exactly why “add this one dependency” advice is misleading if you build a classpath by hand.

Metric keys have moved

In August 2026 the quality gate on the Server project was failing on conditions named software_quality_security_rating, software_quality_reliability_rating, new_violations and sca_severity_vulnerability — not the bugs/vulnerabilities/code_smells triple every older guide queries. Those legacy keys still returned values. On 15 October 2026 the gate of SonarSource_sonarqube-scan-action on SonarQube Cloud listed 13 conditions, among them reliability_rating, security_rating, new_violations and sca_severity_vulnerability, and none with a software_quality_ prefix. If you are building a gate check, read the condition list back from project_status rather than assuming which metrics are in it.

Tokens

Generate tokens under your avatar → My Account → Security, or over the API with api/user_tokens/generate (POST). Choose the narrowest type: a project analysis token can only submit analyses for one project, which is what a CI job needs; a user token carries everything you can do. Set an expiry. The token is shown once. Revoke with api/user_tokens/revoke.

If you use the Python wrapper, know what you are adopting: python-sonarqube-api‘s newest release on PyPI is 2.0.5, uploaded 2024-08-04. For a server whose API changed in September 2025, a two-year-old wrapper is a liability. requests plus the endpoint list from api/webservices/list is less code and never goes stale.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.