How to reverse engineer the Sonar Web API

Every action that is taken in SonarQube is driven by the Web API. There is nothing you can do in SonarQube that you cannot do using the Web API.

:warning: We put a great deal of effort into the UI and UX of our products and sincerely think that most actions should be completed there. Especially when it comes to viewing analysis results, the UI is the best place to view up-to-date information with the right context. We think it is much better that you give access to others to view analysis data within our products, rather than craft some export.

And, we recognize that there are common administrative actions where using Web APIs to help with automation makes sense. There are also surely some interesting reports not available in the UI where you would need to export the data from SonarQube.

A link to the Web API documentation for your SonarQube Server / Community Build instance can always be found in the footer of your instance. The SonarQube Cloud Web API is documented here.

You’ll find that most endpoints are properly documented, while some are not or are lacking in documentation.

If you’re not sure which Web API to use, you can reverse engineer what’s happening in the UI by diving into your browser’s dev tools.

Example: Retrieve historical coverage measures

  • Go to the Activity tab of a project

  • Open your browser’s dev tools (here we’ll use Chrome), switch to the Network tab, and select the Fetch/XHR filter:

  • Switch the metric filter to Coverage

Suddenly, it’s very clear from the Request URL which API was called. The Payload tab and Preview/Response tabs make it clear what query parameters are used and what the response was.

Thanks to Discourse for the inspiration

11 Likes
How to get metrics from sonarqube api
Download the Project specific Security Report using API
User data export
SonarCloud API for monorepo project import
Using reference branch parameter in pipelines sonar.newCode.referenceBranch
Sonarcloud API create project and initial scan
Powershell script to pull the sonarqube metrics and show the results in Pull Request
Need to get portfolio breakdown values using API endpoint
Setting project settings via REST calls
[WebApi] Endpoint to set default project visibility?
SonarQube API endpoint
How to get members and permissions of a Portfolio
SonarCloud long-lived and short-lived branches
Current Method for Disabling PR Decoration in Azure DevOps?
SonarCloud API to get details of Vulnerability analysis results in the Azure DevOps Pull Request
Sonar total loc analyzed
Azure DevOps connectivity management - API for token rotation
Export sonarqube report in excel using Azure devops pipeline
Using Sonar as a code analysis tool for dynamic code deliverables
API to provide multiple permission
New_code_smells measure not giving correct output while invoking from Sonar search API
Check user information API Rest SonarCloud
Web API: Using api/measures/ how do i GET code coverage for multiple componentKeys (projects)?
Sonarqube Security Report
Apply Quality Gates Automatically for the specific Projects in SonarQube
Getting a list of rules for a given Quality Profile
Rest Api call to download project pdf report
Cyclomatic Complexity Report
Azure integration without personal access token?
SonarQube API - rating issue
Data Dictionary to get information
Technical dept report per tag
Update PAT in Azure DevOps organization binding via API
Retrieve analysis resuslts from python with web api
Extracting last analysis on a specific branch
SonarQube WebAPI v2 - OpenAPI specification, various questions regarding information etc
How can I export a list of issues from SonarQube?
Get sonarqube projects metrics using api
Import bitbucket project through web_api
Exported sonarqube report for developer version is in .pb format, how to read it
Otganization token update automation
msg:The project parameter is missing
Can we export data from SonarQube to Power BI?
Need to generate a delta report for sonarqube analysis
What is the metric value for security ratings (measure) in SonarQube
Get the Git Repository Name from the SonarQube
LOC Notification Threshold resets after upgrade – add Web API support
How To Get Application Metrics In Sonarqube
How to filter on project key using api/components/search_projects?
Azure DevOps group sync in SonarCloud
Get Notifications When an Issue is Marked as 'False Positive' or 'Won't Fix'
Renew Azure DevOps token via WebAPI
How to download Project issues via web_api
About multiple different versions of SQ data merging
Set New Code definition per command line/API
Sonar REST API - date of scanning and Coverage on the same RESTAPI
SonarQube Exporting a Parseable Results File
Sonar analysis overview shows less number of Majors,blockers,criticals
Get all active rules by Quality Profile via API
Query to get all the issues for the project and branch
How to get the list of projects failing due to the specific rule
Setting Quality Gate Permissions via API
Why do I need admin privileges to list projects using the web API?
How to set DevOps Platform Integration properties thru properties file
Retrieving issues and measures data file for a component for given history date
SonarQube Reporting
Present analysis to customer (report)
How to get sonar metrics based on commit id or date of commit
Setup branchesToKeepWhenInactive through sonar-project.properties
How can we trigger notification from CI Tool using REST API
Api/project_tags/set overwrites existing tags
Visualization and reporting
SonarQube Health alert from ADO pipeline
How to check Overall lines of Code of all projects
Dynamically determine which rules are run
Getting Test Coverage data into Power BI
Web API for SonarQube SubPortfolios
Easily see which group has access to which projects?
Sonarcloud WebAPI to PowerBI
Automate sonarqube configuration with gitlab
Obtain "letter grade" for project metrics?
How to get organization LOC from Sonarcloud API?
Is it possible to configure devops integration in sonarscanner
Get severity amount
How to download the reports from the sonarqube
Getting coverage report by using sonar rest api
How to update Portfolio ID used on URL
Organization User Search with External identity ID
What location is sonarscan report saved during gerrit pullbranch analysis?
Private lines of code analyzed with web_api
Unable to get full pull branch analysys report using webapi
False-positive sonar api
Access to audit logs
Automatically add tags to generic external issues
How to use SQ web API to bring only the list with the active quality profiles of a project
Project admin permission for a group of projects
Disable "automatic analysis" by default
Sending SonarCloud reports to EventHub
Status code: 200 when trying to create project from API
Sonar Cloud Vulnerability and bug fix report for Audit
Retrieve latest coverage details of particular file with buildstring information
SonarQube Metrics For Monitoring
Getting sonarqube project new metric values by dating using sonarqube api
Azure Devops Scanning portfolio
SonarQube - How we can get set of project failure report using the sonar api
Problems with SonarCloud API
What is an API to get the Portfolio wise Rule ID count
Can web_api return only members of my organization when using a free plan?
Is there away to export the project summary data to csv?
Error al realizar la solicitud: Expecting value
API to get status of single pull request
Sonarcloud reporting?
Generating reports from SQ
Export project analysis reports from SonarCloud
Issue Generating GLOBAL_ANALYSIS_TOKEN via SonarQube API - 'name' Parameter Missing
Need to fetch the user lists from my sonar cloud organization
How to create user and api token during installation process?
Change default "default branch"
How do I disable Automatic Analysis on a project using the Web API?
Difficult to obtain integration details from Sonarqube API
Advice regarding reverse merges and issue resolutions
Unable to login as admin even after resetting password via db directly
Generate report for specific repos over email in sonarqube community edition without using any plugi
Cleaning up Obsolete Data Stored in Sonarqube
Sonarcloud api to list private projects
How to get projects where a sonar group is being used for permissions
Azure Pipeline Generate Report
Managing Portfolios using SonarCloud Web-API
Sonar.properties not being reflected on OCP
Export SonarQube rules (v10.3)
Need to pull report of vulnerabilities and execution flows via API
Using Sonar Web API to fetch Failed Quality Gates
Can I disable the “more option” in Login Page of Sonarqube
SonarQube New Code with Reference Branch Option
About Web API questions
Automatically bind new projects to Github
Is there any Api/pluggin available in sonar qube to pull reports out and send to project team
Exporting the the list of projects and related issues which i see on dashboard in power bi using API
Trying to provide permission for project as project admin over API
Create web application for security assitance using Sonarqube API
Export results of SONAR scans
Analyze projects vs manually create sonar cloud project
API to update Gitlab Token
How can I extract an analysis report from sonarcloud
Analyze projects vs manually create sonar cloud project
Sonarqube exporter
New_code_smells measure not giving correct output while invoking from Sonar search API
How to publish sonarqube Quality gate status, Bugs, vulnerabilities, hotspots in grafana
/api/projects/export_findings endpoint not working
Detect MQR vs Standard Experience Mode?
How to retrieve the sonar errors from existing sonarqube server using sonarlint gradle in my plugin
SonarCloud API search projects by size
Generating Project pdf report with command line
Keep analyses and everything else forever (turn off dbcleaner) possible?
SonarQube - PAT RENEWAL API CALL - Issue!
Report export as Artifacts in GitLab
DevOps Platform Integration with Bitbucket configuration via sonar.properties file
New Code Analysis Scope for unusual branching
Some of our projects somehow did not get the New Code Definition setup and now I can't set it?
Get All Tags for a project
Using Professional Edition API Library with SonarQube Community Edition 10.6
Quality Gates/Profiles change for Existing project in sonar
Sonarqube Auto cleanup
API Error: 403 Forbidden > Insufficient Privileges
Missing DevOps Platform Integration
Accessing total "Effort" via API
General SonarCloud Questions
How to get a response related to the comment_line in version v25.3.0.104237
How to use sonarqube cloud api to generate project-specific token
Gather "more global" insights into scanner context data of the latest scan of a projectKey
REST API Working with Tags (Active Tags per project)
Fetching quality gate id using powershell script
How to retrieve the file specific sonar issues from sonarcloud api for opendaylight project
Example API for creating SonarCloud Portfolios
Automatically enable DevOps plaform integration for every project
Measures API returns no new code metrics
Terraform provider for sonarqube
New project creation + v2 APIs
SonarCloud API returns "Project doesn't exist" (404) for projects that exist in the UI
How to bind GitHub repo via API for automatic analysis?
SonarQube Community Docker Image 25.1.0.102122-community Web API logical bug
How to download or Export the Rules and its content from the portal?
Issues with Web API v2
Add comments at the project level
Issue Creating Quality Gate for New Code via Web API – SonarQube 10.6
Is it possible to disable PR decorations programatically?
Unable to add tags in sonarqube for bitbucket repo
Changing organization binding - From Azure DevOps to GitHub
Authentication for Web API v2
Filter project by Tags
I want to Generate and download Sonarcloud reports via API
SonarQube Reporting - Excel Spreadsheets
Fetch projectKey which has tag
API returns the same value
Regulatory Report / API report Customization
New to SonarCloud, seeking guidance on setting up project-specific quality gates, integrating OWASP
Suitable SonarQube api for specific json output
Jenkins Master and GitLab Repository information Required from SonarQube
Sonar analysis results are not same with same branches on multiple sonarqube servers
Migration of Projects from Azure DevOps to Self Hosted GitLab
How to get coverage value from sonarqube using rest API (JAVA)
New Code vs Overall Code for Quality Gate Conditions created using SonarCloud Web API
API Error! "api/measures/component?metricKeys=coverage&component="
SonarCloud - Add members via API
Sonarqube - 404 Client Error when calling sonarqube API
SonarCloud - Add members via API
Difference between Two Code Scans for same branch
Add quality profile by a script
How to fetch metric details such as Bugs, Vulnerabilities, etc. using SonarQube CLI?
(Enterprise 10.4) Sonarqube OWASP top 10 shows different values in API response compared to UI

Hi Colin, i really like this explanation. I am not that much interested in frontend development and that made it hard for me to “grok” the easy way that Ann mentioned in some replies (how to eavesdrop on the Web API usage) :+1: For this, your howto helps a lot!

Concerning the below quoted paragraph (and combining it with your current survey question about “communitysm”) … maybe you might be able to find a way how to “channel” some energy concerning “common administrative actions”? I really would be looking forward to it! (because some lonely helpful threads really get easily lost in the sea of new postings).

Sadly, i was not able to find an easy solution … how to structure that? By tag? In its own “compartment” (e.g. smth like here)? I have no good suggestion to make :confused:

1 Like

Hey Colin,

great post! This is exactly what I have been using for years to get in deeper with many tools.
I remember with a shudder the crappy browser tools of IE 11, but these days press F12 and start diving :joy:

Gilbert

1 Like

I hope this is on-topic (enough), but I’ve been using both the Web API documentation and the network activity in the UI to help me with building automations for SonarCloud. The Web API is especially useful as it let’s me generate a typed client by inspecting https://sonarcloud.io/api/webservices/list. (I have a go-sonarcloud client which, in turn, is used to build a Terraform provider for SonarCloud.)

My question is now: how should I deal with either deprecated endpoints or endpoints that are missing in the webservices/list? I figure for missing endpoints I could open a feature request at https://portal.productboard.com/sonarsource/1-sonarcloud/ , though it doesn’t feel like a feature request.

As an example of where I’m having problems: there are two important endpoints regarding permissions that have been marked deprecated for well over a year, but they still work. The API endpoints that replace them are not registered yet in the Web API Documentation, though they are in use by the UI. I’m still using the deprecated API endpoints, simply because I can generate the client code for them. I’d have to do manual work to add support for the new endpoints, and I kind of hate doing manual work :sweat_smile:.

Do you have any tips for a course of action here @Colin?

1 Like

I don’t see Activity option when am looking at pull branch analysis. can you please indicate how can I get what api to call to get coverage for a specific pull branch?

example: on gui url looks like this for me
https://sonar-team.com/dashboard?id=product-pba&pullRequest=124434-9

hi colin and all :wave:

seeing Gilberts “graphical” api-diff between 9.9 LTS and 10.3 latest here made me wonder:

How would i reverse-engineer those api-changes between SQ-Server-Versions? :thinking:

Are there maybe some “versionized” world-readable docs that i could diff myself with tooling? Like OpenAPI-Docs that i could download as xml/yml/zml and diff via tooling?

edit: example for more context

  • my self-created api-tooling was created targetting an older SQ Version
  • i want to check if i can optimize anything.
  • what could i check, what changes were made that would make my processes better?
  • like in the example above:
    • It seems now one can set the new code period directly while creating a project
    • which means, i could shift functionality from the “project-confectionize-phase” :zany: to the project-setup-phase
2 Likes

That was already possible before, see

but adding it to api/projects/create for convenience is good

I wish to automate new project creation, but web API for Sonarqube EE 9.9.2 doesn’t show api/alm_integrations/import_github_project