Fetch Portfolio project details based on metric using API

Hi There,

I am new to SonarQube, I want to query the Portfolio project details based on metrics values, kindly provide API filter/code samples

Thanks in advance,
Lija.

Hey there.

You are probably looking for GET api/measures/component_tree

// 20210428155140
// https://next.sonarqube.com/sonarqube/api/measures/component_tree?component=MASTER_PROJECT&metricKeys=coverage

{
  "paging": {
    "pageIndex": 1,
    "pageSize": 100,
    "total": 92
  },
  "baseComponent": {
    "key": "MASTER_PROJECT",
    "name": "All Projects",
    "description": "",
    "qualifier": "VW",
    "measures": [
      {
        "metric": "coverage",
        "value": "87.1",
        "bestValue": false
      }
    ]
  },
  "components": [
    {
      "key": "MASTER_PROJECTcom.sonarsource.tooling.jira:analyzer-release-observer",
      "refKey": "com.sonarsource.tooling.jira:analyzer-release-observer",
      "name": "analyzer-release-observer",
      "qualifier": "TRK",
      "measures": [
        {
          "metric": "coverage",
          "value": "0.0",
          "bestValue": false
        }
      ]
    },
    {
      "key": "MASTER_PROJECTorg.sonarsource.auth.bitbucket:sonar-auth-bitbucket-plugin",
      "refKey": "org.sonarsource.auth.bitbucket:sonar-auth-bitbucket-plugin",
      "name": "Bitbucket Authentication for SonarQube",
      "qualifier": "TRK",
      "measures": [
        {
          "metric": "coverage",
          "value": "95.7",
          "bestValue": false
        }
      ]
    },
    {
      "key": "MASTER_PROJECTbuild-wrapper-linux",
      "refKey": "build-wrapper-linux",
      "name": "build-wrapper-linux",
      "qualifier": "TRK",
      "measures": [
        {
          "metric": "coverage",
          "value": "76.7",
          "bestValue": false
        }
      ]
    },
....

Thaks @Colin_SonarSource , it worked. Thank you for your help!

I have two more questions, can we extract Portfolio health factors like Reliability, Security Vulnerabilities, Security Review and Maintainability etc. and the grading like
Reliability - D
Security Vulnerabilities - C
Security Review - E and so on…
is it possible using APIs?

Also, in the Portfolio along with the domains, we get the indicator of the worst-performing project(s) in each domain. Is there an API query available to fetch worst-performing projects from projects lists of each domain?

Some samples would be great help.

Thanks in advance,
Lija.

The metric keys (like coverage) are available in the documentation on Metric Definitions and can be supplied to the metricKeys query parameter.

You’ll need to iterate through the results of your API calls to parse this information.

Thank you @Colin_SonarSource for your help!.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.