How to check if the device has particular type of measurement like “type”: “c8y_weight” is present or not using java code.
It depends on what you are using to call that measurement API.
If you are using Java SDK provided by Cumulocity then you can just use the class MeasurementFilter that has a couple of methods. You just need to call the method .byType and provide the string value for which you want to fetch that measurement. For example:
MeasurementFilter measurementFilter = new MeasurementFilter()
.bySource(new GId(deviceId)) //device id will be a string
then you can just call the method of measurement API interface to fetch the measurements based on this filter which returns a iterable of MeasurementRepresentation. For example:
Iterable<MeasurementRepresentation> measColl = measurementApi.getMeasurementsByFilter(measurementFilter).get(2000).allPages(); //this will return all the records
Now if you are fetching the measurements based on the REST call then you can just add the type param in the Rest call itself. From Postman the URL would be like this →
For doing a REST call with Java I believe you can get some solution on the internet on how to send a get call. There are numerous ways, but I do not have the code snippet right now
Hope you understand the solution
For better understanding go through these Cumulocity apis: