Meaning of { index; value } pair in measure response from web api

Hello people and happy new year,

Im using the SonarQube Web API to extract analysis information and generate a docbook report from it.
However I am not sure about the meaning of some of the data.

When using the web api function “api/measures/component” I get a response like this:

"measures": [
  {
    "metric": "complexity",
    "value": "12",
    "periods": [
      {
        "index": 1,
        "value": "2"
      },
      {
        "index": 2,
        "value": "0"
      },
      {
        "index": 3,
        "value": "0"
      }
    ]
  },

The problem is I dont know what the index field refers to. Some entries dont even have an index and contain only a single value. Unfortunately the official documentation doesnt offer any Information about that.

I will appreciate any help. Thank you

Bump!

Hi Henrik,

I’m guessing you are using a quite old version of SonarQube.
It used to be possible to have values for multiple configured periods. The index refers to the details about the period in “periods”.
The Webservices of any newer SonarQube (including all versions since the current LTS v6.7) should only return one period, which is the leak period.
The data structure is the same and the index will always be 1. The value corresponds to what is measures within the configured leak period (usually since the version of the project changed).

Example:

"measures": [
  {
    "metric": "new_lines",
    "periods": [
      {
        "index": 1,
        "value": "488"
      }
    ]
  }
],
"pullRequest": "1113"
},
"periods": [
  {
    "index": 1,
    "mode": "previous_version",
    "date": "2018-12-24T19:18:33+0100"
  }
]
2 Likes

To add on to @dmeneses’s excellent response, some clarity can be shed on what the “periods” are by adding the query parameter/value additionalFields=periods to your Web API request, like so:

https://next.sonarqube.com/sonarqube/api/measures/component?componentKey=sonarts&metricKeys=lines_to_cover&additionalFields=periods

At least, this works on the most recent version of SonarQube (and since 6.7 LTS).

Also, please try not to bump threads, and certainly not after only 2 hours.

Regards,

Colin

3 Likes

Thank you all for the good responses. It was very helpful.

Greetings

could explain this with an multiple index example pls?also I see bestValue what does it mean?