# How to get the latest measurement in microservice

**URL:** <https://community.cumulocity.com/t/how-to-get-the-latest-measurement-in-microservice/3625>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [November 22, 2023, 10:26am UTC](https://community.cumulocity.com/t/how-to-get-the-latest-measurement-in-microservice/3625 "2023-11-22T10:26:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaibhavi\_ghumare](https://avatars.discourse-cdn.com/v4/letter/v/a587f6/32.png) [@vaibhavi\_ghumare](https://community.cumulocity.com/u/vaibhavi_ghumare)\
**Post date:** [November 22, 2023, 10:26am UTC](https://community.cumulocity.com/t/how-to-get-the-latest-measurement-in-microservice/3625/1 "2023-11-22T10:26:01Z")

</div>

how to get the latest measurement from measurementApi.getMeasurementsByFilter(measurementFilter)

---

<div class="post-metadata">

**Author:** ![Murat\_Bayram](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/murat_bayram/32/3670_2.png) [@Murat\_Bayram](https://community.cumulocity.com/u/Murat_Bayram)\
**Post date:** [November 22, 2023, 1:09pm UTC](https://community.cumulocity.com/t/how-to-get-the-latest-measurement-in-microservice/3625/2 "2023-11-22T13:09:38Z")

</div>

Hi,

could you provide a bit more infos. Are you using the JavaSDK here?

---

<div class="post-metadata">

**Author:** ![Harald\_Meyer](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/harald_meyer/32/1959_2.png) [@Harald\_Meyer](https://community.cumulocity.com/u/Harald_Meyer)\
**Post date:** [November 22, 2023, 1:18pm UTC](https://community.cumulocity.com/t/how-to-get-the-latest-measurement-in-microservice/3625/3 "2023-11-22T13:18:19Z")

</div>

In general, when using the API, the trick is to do revert=true and pageSize=1. This will give you the last measurement.

Here is an example how to do it with the Java SDK (replace 2000 in the get() call with 1 to get only the lastest):

> <https://github.com/Cumulocity-IoT/cumulocity-microservice-templates/blob/94b1a2ae21d95a065ae310732ccc2a05e6b73d0c/basic/src/main/java/com/c8y/ms/templates/basic/service/MeasurementService.java#L39>

---

<div class="post-metadata">

**Author:** ![vaibhavi\_ghumare](https://avatars.discourse-cdn.com/v4/letter/v/a587f6/32.png) [@vaibhavi\_ghumare](https://community.cumulocity.com/u/vaibhavi_ghumare)\
**Post date:** [November 22, 2023, 1:41pm UTC](https://community.cumulocity.com/t/how-to-get-the-latest-measurement-in-microservice/3625/4 "2023-11-22T13:41:04Z")

</div>

Yes, I am writing a function for microservice in which I have to return the latest measurement for the defined measurementFilter

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [May 20, 2024, 1:41pm UTC](https://community.cumulocity.com/t/how-to-get-the-latest-measurement-in-microservice/3625/5 "2024-05-20T13:41:11Z")

</div>

Closed on May 20, 2024, 1:41pm UTC

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