Search code examples
sonarqubesonarqube-scansonarlint

How to get SonarQube Issues Report via API


Is there a way to get an issues report by querying the SonarQube web API?

With previous versions of SonarQube, I was able to generate an HTML report after each build but this feature looks like it's been deprecated in newer installments.

At the moment, I'm trying this bit of code

curl -u foo:bar https://sonar.example.com/api/issues/search?pageSize=100&componentKeys=my-app&metricKeys=violations,ncloc,line

But it errors with {"errors":[{"msg":"The 'component' parameter is missing"}]

Ideally, what I'm after is to just get the lines of code, the number of bugs, vulnerabilities, and Code smells in each run/scan.

Something like thisenter image description here

But through querying the API after each analysis.

Is this possible, please?


Solution

  • Had the same issue. The problem is that there is something wrong with the CURL command and you need to specify the full url as string using quotes.

    Your case would be:

    curl -u foo:bar "https://sonar.example.com/api/measures/search?pageSize=100&componentKeys=my-app&metricKeys=ncloc,violations,complexity"
    

    This is an example with measures. Be sure to check the required parameters.