How to query multiple fragments in 1 api call in measurements

Product/components used and version/fix level:

Cumulocity Production

Detailed explanation of the problem:

Hi, I have measurements in this way.

{
"measurements": [
        {
            "self": "/measurement/measurements",
            "time": "2023-08-28T23:39:35.000Z",
            "id": "id",
            "source": {
                "self":  "/inventory/managedObjects/",
                "id": "id"
            },
            "type": "A",
            "A": {
                "abc": {
                    "unit": "",
                    "value": 0.0
                }
            },
{
            "self": "/measurement/measurements",
            "time": "2023-08-28T23:39:35.000Z",
            "id": "id",
            "source": {
                "self":  "/inventory/managedObjects/",
                "id": "id"
            },
            "type": "A",
            "B: {
                "xyz": {
                    "unit": "",
                    "value": 0.0
                }
            }
]
}

Now I want to fetch the latest value for all the fragments of type A. I tried

/measurement/measurements?withTotalElements=true&withTotalPages=true&revert=true&dateTo=2023-08-29T00:00:00.000Z&valueFragmentType=A&pageSize=2000&valueFragmentSeries=abc&valueFragmentSeries=xyz

this api but it is fetching only abc fragment values but not xyz values. I also tried custom query but that is also not working. Can we use custom query on measurements? If yes could you please tell me how can i carry out my use case with this? OR could you please tell me how can i achieve this use case with any other way.

Thanks,
Samanyu

Hi,
if you want to query multiple measurement series in one call, also take a look at the retrieve a list of series and their values measurement endpoint.
It accepts a comma separated list of series-names:
GET /measurement/measurements/series?source=...&dateFrom=...&dateTo=...&series=A.abc,B.xyz

Hi Korbinian,

The series endpoint won’t give me the latest value, it will only fetch the values between a time period. even if i just set dateTo as current time i have to query the series to find a value if its not present for some time like for example if the value i am searching for was entered 2 months ago, then i have to search the series endpoint till that time. I could do the same thing with measurement endpoint as well, but i dont want it to be like that. I want to fetch directly the latest values itself.

Is it possible to use custom query in measurements?
Also, could you suggest any other way?

Thanks,
Samanyu

If you only want to retrieve the latest measurement you will need to perform one request per combination of fragment/series.
You can use a pageSize of 1 in this case as you are only interested in the latest value.
So in your case e.g. one request to:
/measurement/measurements?revert=true&dateFrom=1970-01-01T00:00:00.000Z&pageSize=1&valueFragmentType=A&valueFragmentSeries=abc
and another one to:
/measurement/measurements?revert=true&dateFrom=1970-01-01T00:00:00.000Z&pageSize=1&valueFragmentType=A&valueFragmentSeries=xyz

There is no endpoint to retrieve the latest value of different measurement series in a single request as of now.

1 Like

Okay thanks for the confirmation. Could you please also tell me if it’s possible to use custom query on measurements like we do in inventory. like query = $filter= $order by creationtime desc something like that

The API is documented here: Cumulocity - OpenAPI and as you can see, this is not supported.

1 Like

Thanks for the confirmation :slight_smile:

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