Getting file level metrics from SonarQube REST API

HI,
I need to get file level metrics from SonarQube using SonarQube REST API.
Can anyone give me suggestion to get file level metrics.

Thanks in Advance.

Hello,
You can use /api/measures/component to request the measures you want on any component.

You have to use it like this:
GET /api/measures/component?componentKey=<url_encoded_file_id>&metricKeys=<url_encoded_list_of_metrics_separated_by_comma>

Here is an example for an open source project on SonarCloud.

1 Like

Hi

Thanks for your response, we are able to get the value of particular file but we re looking for all files with their respective metrics.
With following command we are getting only few files with their respective metrics.
/api/measures/component_tree?component=&metricKeys=

Could you guide us to get all files with their respective metrics.

Thanks in Advance.

I think you should be able to get the list of all files with /api/components/tree, you might have to do multiple calls due to pagination of the web service.
So if you have a lot of files in your project, have a look at p and ps parameters to get all files.

You can also set the parameter qualifiers=FIL to retrieve only files and filter out directories and test files.

1 Like