Device REST API


#1

How would I use the API to find out the last time a device reported any data?


#2

Hi Lars,

If you’re in a workflow, you can grab this information using the device get node:

https://docs.losant.com/workflows/data/get-device/

The result will contain a property called connectionInfo . Like so:

The time is the last time Losant saw a connection from the device.

If you’re not within a workflow and you would still like to use the Losant API. The Device Get API will return the same info above. More info:

https://docs.losant.com/rest-api/device/#get


#3

Sorry, totally misread your question! The above is to get the last known connection status.

To get the last time the device reported state:

https://docs.losant.com/rest-api/device/#get-composite-state

This is also doable with the Device: Get Node. But, the composite will contain all attributes, the last value reported, and time reported.

Or:

https://docs.losant.com/rest-api/data/#last-value-query

With this endpoint, you can query via attribute and grab multiple devices.

So, you have options :slight_smile:


#4

So to clarify, I’m not in a Losant workflow, and just want to know the last time the devices successfully posted any sensor data.


#5

Yup! The two API calls in my last response should get you exactly what you need.


#6

If you just want to visually see it, the Debug Tab on the device page will show you “Recent Device States”. This includes the most recently received states with their timestamps.