You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/iot-central/core/howto-query-with-rest-api.md
+13-32Lines changed: 13 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,10 @@
1
1
---
2
2
title: Use the REST API to query devices in Azure IoT Central
3
-
description: How to use the IoT Central REST API to query devices in an application
3
+
description: How to use the IoT Central REST API to query devices in an application, including filters, aggregation, and sorting.
4
+
titleSuffix: Azure IoT Central
4
5
author: dominicbetts
5
6
ms.author: dobett
6
-
ms.date: 06/14/2022
7
+
ms.date: 05/19/2023
7
8
ms.topic: how-to
8
9
ms.service: iot-central
9
10
services: iot-central
@@ -15,7 +16,6 @@ services: iot-central
15
16
The IoT Central REST API lets you develop client applications that integrate with IoT Central applications. You can use the REST API to query devices in your IoT Central application. The following are examples of how you can use the query REST API:
16
17
17
18
- Get the last 10 telemetry values reported by a device.
18
-
- Get the last 24 hours of data from devices that are in the same room. Room is a device or cloud property.
19
19
- Find all devices that are in an error state and have outdated firmware.
20
20
- Telemetry trends from devices, averaged in 10-minute windows.
21
21
- Get the current firmware version of all your thermostat devices.
@@ -28,9 +28,6 @@ Every IoT Central REST API call requires an authorization header. To learn more,
28
28
29
29
For the reference documentation for the IoT Central REST API, see [Azure IoT Central REST API reference](/rest/api/iotcentral/).
30
30
31
-
> [!IMPORTANT]
32
-
> Support for property queries is now deprecated in the IoT Central REST API and will be removed from the existing API releases.
To learn how to query devices by using the IoT Central UI, see [How to use data explorer to analyze device data.](../core/howto-create-analytics.md)
@@ -102,24 +99,19 @@ The following sections describe these clauses in more detail.
102
99
103
100
## SELECT clause
104
101
105
-
> [!IMPORTANT]
106
-
> Support for property queries is now deprecated in the IoT Central REST API and will be removed from the existing API releases.
107
-
108
102
The `SELECT` clause lists the data values to include in the query output and can include the following items:
109
103
110
104
- Telemetry. Use the telemetry names from the device template.
111
-
- Reported properties. Use the property names from the device template.
112
-
- Cloud properties. Use the cloud property names from the device template.
113
105
-`$id`. The device ID.
114
106
-`$provisioned`. A boolean value that shows if the device is provisioned yet.
115
107
-`$simulated`. A boolean value that shows if the device is a simulated device.
116
108
-`$ts`. The timestamp associated with a telemetry value.
117
109
118
-
If your device template uses components such as the **Device information** component, then you reference telemetry or properties defined in the component as follows:
110
+
If your device template uses components, then you reference telemetry defined in the component as follows:
119
111
120
112
```json
121
113
{
122
-
"query": "SELECT deviceInformation.model, deviceInformation.swVersion FROM dtmi:azurertos:devkit:hlby5jgib2o"
114
+
"query": "SELECT ComponentName.TelemetryName FROM dtmi:azurertos:devkit:hlby5jgib2o"
123
115
}
124
116
```
125
117
@@ -131,9 +123,7 @@ The following limits apply in the `SELECT` clause:
131
123
132
124
- There's no wildcard operator.
133
125
- You can't have more than 15 items in the select list.
134
-
- In a single query, you either select telemetry or properties but not both. A property query can include both reported properties and cloud properties.
135
-
- A property-based query returns a maximum of 1,000 records.
136
-
- A telemetry-based query returns a maximum of 10,000 records.
126
+
- A query returns a maximum of 10,000 records.
137
127
138
128
### Aliases
139
129
@@ -179,7 +169,7 @@ Use the `TOP` to limit the number of results the query returns. For example, the
179
169
}
180
170
```
181
171
182
-
If you don't use `TOP`, the query returns a maximum of 10,000 results for a telemetry-based query and a maximum of 1,000 results for a property-based query.
172
+
If you don't use `TOP`, the query returns a maximum of 10,000 results.
183
173
184
174
To sort the results before `TOP` limits the number of results, use [ORDER BY](#order-by-clause).
185
175
@@ -211,22 +201,16 @@ The time window value uses the [ISO 8601 durations format](https://en.wikipedia.
211
201
212
202
| Example | Description |
213
203
| ------- | -------------------------- |
214
-
| PT10M | Past 10 minutes |
204
+
| PT10M | Past 10 minutes |
215
205
| P1D | Past day |
216
-
| P2DT12H | Past 2 days and 12 hours |
206
+
| P2DT12H | Past 2 days and 12 hours |
217
207
| P1W | Past week |
218
208
| PT5H | Past five hours |
219
209
| '2021-06-13T13:00:00Z/2021-06-13T15:30:00Z' | Specific time range |
220
210
221
-
> [!NOTE]
222
-
> You can only use time windows when you're querying for telemetry.
223
-
224
211
### Value comparisons
225
212
226
-
> [!IMPORTANT]
227
-
> Support for property queries is now deprecated in the IoT Central REST API and will be removed from the existing API releases.
228
-
229
-
You can get telemetry or property values based on specific values. For example, the following query returns all messages where the temperature is greater than zero, the pressure is greater than 50, and the device ID is one of **sample-002** and **sample-003**:
213
+
You can get telemetry based on specific values. For example, the following query returns all messages where the temperature is greater than zero, the pressure is greater than 50, and the device ID is one of **sample-002** and **sample-003**:
230
214
231
215
```json
232
216
{
@@ -245,10 +229,8 @@ The following operators are supported:
245
229
The following limits apply in the `WHERE` clause:
246
230
247
231
- You can use a maximum of 10 operators in a single query.
248
-
- In a telemetry query, the `WHERE` clause can only contain telemetry and device metadata filters.
249
-
- In a property query, the `WHERE` clause can only contain reported properties, cloud properties, and device metadata filters.
250
-
- In a telemetry query, you can retrieve up to 10,000 records.
251
-
- In property query, you can retrieve up to 1,000 records.
232
+
- In a query, the `WHERE` clause can only contain telemetry and device metadata filters.
233
+
- In a query, you can retrieve up to 10,000 records.
252
234
253
235
## Aggregations and GROUP BY clause
254
236
@@ -312,8 +294,7 @@ The current limits for queries are:
312
294
- No more than 10 logical operations in the `WHERE` clause.
313
295
- The maximum length of a query string is 350 characters.
314
296
- You can't use the wildcard (`*`) in the `SELECT` clause list.
315
-
- Telemetry-based queries can retrieve up to 10,000 records.
316
-
- Property-based queries can retrieve up to 1,000 records.
0 commit comments