Measures API returns no new code metrics

  • which versions are you using (SonarQube Server / Community Build, Scanner, Plugin, and any relevant extension)
    SonarQube Developer Edition v10.8.1 (101195)

  • how is SonarQube deployed: zip, Docker, Helm
    zip

  • what are you trying to achieve
    Retrieve ‘new code’ metrics from the measures API, e.g. new_violations, new_software_quality_high_issues, etc. I’d essentially like to know for the new code time period / new code version defined for each project, what the number of new issues we have introduced are… much like you can see at a glance through the UI.

  • what have you tried so far to achieve this

I’ve read this thread: Web API: search history won't return values for metrics on new code

Because my initial approach was to call the API like so:

curl --location 'https://SONAR/api/measures/search_history?metrics=new_software_quality_medium_issues&component=PROJECT_KEY'

But those ‘new’ items don’t get populated in the response, as per that thread.

So now I’m calling the following endpoint:

curl --location 'https://SONAR/api/measures/component?component=PROJECT_KEY&metricKeys=new_violations,new_software_quality_high_issues,new_coverage'

I just want to confirm, is this the correct way to get the data that I’m after?

Hey there.

You’re right on the money – GET api/measures/search_history retreives historical metrics, of which new_ metrics will not be included. This is what you would see when browsing, say, the Activity tab of your project.

GET api/measures/component retrieves the present values – what you would see when browsing the project dashboard or the Activity tab.

If you ever have any doubt, this guide is useful:

:warning: Your version is past EOL. You should upgrade to either the latest version or the current LTA (long-term active version) at your earliest convenience. Your upgrade path is:

10.8.1 → 2025.1.1-> 2025.2 (last step optional)

You may find these resources helpful:

Colin Is there a way to distinguish which metrics are New Code metrics using the web_api/api/metrics API? I didn’t see anything in the response indicating this. Should we assume that any metric whose name starts with ‘New’ represents a New Code metric?

Exactly. Any metric with a key starting with new_ only applies to new code.

I’m a bit confused about whether to use the key or name of the metric from web_api/api/metrics. In some cases, when I use the key, I see historical data coming through — like with “new_development_cost” as key and name is “Development Cost on New Code”

{
    "paging": {
        "pageIndex": 1,
        "pageSize": 100,
        "total": 4
    },
    "measures": [
        {
            "metric": "new_development_cost",
            "history": [
                {
                    "date": "2025-02-10T18:46:09-0600"
                },
                {
                    "date": "2025-02-25T00:56:02-0600",
                    "value": "0.0"
                },
                {
                    "date": "2025-03-14T01:40:14-0500",
                    "value": "180.0"
                },
                {
                    "date": "2025-03-19T19:33:49-0500",
                    "value": "240.0"
                },
                ....
            ]
        }
    ]
}

Also another question is for “New code” metrics there will be always period present in response?

I think the key is more reliable.

I’m not sure which API you’re talking about, but periods was removed in SonarQube 10.0.

Sorry for not adding context, https://sonarcloud.io/web_api/api/measures/component?deprecated=false&section=response This api will always send period in response for “New code” metrics?