How to use SonarQube web API? : <p>Previously, I asked about <a href="https://stackoverflow.com/questions/46198487/export-custom-sonarqube-report/46212879#46212879">how to export custom data from SonarQube Database</a>, and the Sonar Team suggests me that I should use Web API. </p>

<p>After some research, I'm still struggling on how to use the Web API. (
I'm very unfamiliar with how the Web API works)</p>

<p>After reading this <a href="https://stackoverflow.com/questions/30526187/how-to-get-a-json-from-api-metrics-of-sonarqube">post</a>, I realise that I can use Java code to do that. (I've just gone through how to use Apache Http Client) However, after run</p>

<p><code>HttpGet httpGet = new HttpGet("http://localhost:9000/api/issues?metrics=lines");</code>(copied from that post)</p>

<p>I got:</p>

<p><code>HTTP/1.1 404 
{"errors":[{"msg":"Unknown url : /api/issues"}]}</code></p>

<p>After I change this line to:</p>

<p><code>HttpGet httpGet = new HttpGet("http://localhost:9000/project/issues?facetMode=effort&amp;id=project%3Atesting&amp;resolved=false&amp;types=CODE_SMELL");</code></p>

<p>I got:</p>

<p><code>HTTP/1.1 200 
&lt;!DOCTYPE html&gt;&lt;html lang="en"&gt;&lt;head&gt;&lt;meta http-equiv="content-type" content="text/html; charset=UTF-8" charset="UTF-8"/&gt;&lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;&lt;link rel="apple-touch-icon" href="/apple-touch-icon.png"&gt;&lt;link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png"&gt;&lt;link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png"&gt;&lt;link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png"&gt;&lt;link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png"&gt;&lt;link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png"&gt;&lt;link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png"&gt;&lt;link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png"&gt;&lt;link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png"&gt;&lt;link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon-180x180.png"&gt;&lt;link rel="icon" type="image/x-icon" href="/favicon.ico"&gt;&lt;meta name="application-name" content="SonarQube"/&gt;&lt;meta name="msapplication-TileColor" content="#FFFFFF"/&gt;&lt;meta name="msapplication-TileImage" content="/mstile-512x512.png"/&gt;&lt;link href="/css/sonar.bf342fee.css" rel="stylesheet"&gt;&lt;title&gt;SonarQube&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;div id="content"&gt;&lt;div class="global-loading"&gt;&lt;i class="spinner global-loading-spinner"&gt;&lt;/i&gt; &lt;span class="global-loading-text"&gt;Loading...&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;script&gt;window.baseUrl=""&lt;/script&gt;&lt;script src="/js/vendor.0ba4fd94.js"&gt;&lt;/script&gt;&lt;script src="/js/app.bf342fee.js"&gt;&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;</code></p>

<p>Which is not what I expect as well.</p>

<p>I'm wondering what's the right way to use the <a href="https://sonarcloud.io/web_api/" rel="noreferrer">Web API</a>? For example, if I want to get the code smells for a project. How the code should be in Java?</p>

<p>Here is the code I'm using at the moment:</p>

<pre><code>import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class Test {
    public static void main(String[] args) throws ClientProtocolException, IOException {

        //HttpGet httpGet = new HttpGet("http://localhost:9000/api/issues?metrics=lines");
        HttpGet httpGet = new HttpGet("http://localhost:9000/project/issues?facetMode=effort&amp;id=project%3Atesting&amp;resolved=false&amp;types=CODE_SMELL");

        try(CloseableHttpClient httpClient = HttpClients.createDefault();
            CloseableHttpResponse response = httpClient.execute(httpGet);) {
            System.out.println(response.getStatusLine());
            HttpEntity entity = response.getEntity();
            System.out.println(EntityUtils.toString(entity));
        }
    }
}
</code></pre>

<p>Appreciate for any help or guidance!</p>
