Forum Discussion
Go_Ozeki
Oct 22, 2021Copper Contributor
How do I get multiple records in target period?
Hi all,
I would like to retrieve multiple records within a period of time from a Device in IoT Central.
Ex)
- Get the data of 100 records from the latest in Json format.
- Obtain the data within the period (01/01/2021 to 10/31/2021) in Json format.
Json Data Image)
{
{
"timestamp": "2020-01-01T12:00:00.00Z",
"temperature": 20.0,
"humidity": 30
},
{
"timestamp": "2020-01-02T12:00:00.00Z",
"temperature": 30.0,
"humidity": 40
},
{
"timestamp": "2020-01-03T12:00:00.00Z",
"temperature": 40.0,
"humidity": 50
}
}
Is it possible to achieve this with a REST API?
If not, how can I retrieve the data?
I was able to get the data for the latest one using the REST API's Devices - Get Telemetry Value command.
https://docs.microsoft.com/en-us/rest/api/iotcentral/1.0dataplane/devices/get-telemetry-value
- Hi,
You can't use the APIs at this point to get the historical telemetry data directly from IoT Central (you can get the history for commands and properties only). Furthermore, Azure IoT Central retains data on a rolling 30-days basis, which means you can't access data that is older than 30 days by default directly from IoT Central.
The recommend way to implement the scenario you are looking for is to use the continuous data export feature (https://docs.microsoft.com/azure/iot-central/core/howto-export-data) and then depending on where you send the data (Event Hub, Blob, ...) you can use these services API to revtreive the data you need
4 Replies
- OlivierBlochIron ContributorWell, I should have waited a couple days before answering this one as I have good news that contradict my previous response :-). The IoT Central team just released an update to the APIs and now you can query devices data! https://docs.microsoft.com/en-us/azure/iot-central/core/howto-query-with-rest-api
- Go_OzekiCopper Contributor
Hi OlivierBloch,
That's very exciting news for me!
I'll try the API as soon as possible.Thanks for letting me know!
- OlivierBlochIron ContributorHi,
You can't use the APIs at this point to get the historical telemetry data directly from IoT Central (you can get the history for commands and properties only). Furthermore, Azure IoT Central retains data on a rolling 30-days basis, which means you can't access data that is older than 30 days by default directly from IoT Central.
The recommend way to implement the scenario you are looking for is to use the continuous data export feature (https://docs.microsoft.com/azure/iot-central/core/howto-export-data) and then depending on where you send the data (Event Hub, Blob, ...) you can use these services API to revtreive the data you need- Go_OzekiCopper Contributor
Hi OlivierBloch,
I understand that I cannot get the history data with IoT Central's API currently.
I will try to export the data to another service and use that service's API to get the history data.Thank you for help.