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
+23-13Lines changed: 23 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Use the REST API to query devices in Azure IoT Central
3
3
description: How to use the IoT Central REST API to query devices in an application
4
4
author: dominicbetts
5
5
ms.author: dobett
6
-
ms.date: 09/14/2021
6
+
ms.date: 10/12/2021
7
7
ms.topic: how-to
8
8
ms.service: iot-central
9
9
services: iot-central
@@ -18,6 +18,7 @@ The IoT Central REST API lets you develop client applications that integrate wit
18
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
+
- Get the current firmware version of all your thermostat devices.
21
22
22
23
This article describes how to use the `/query` API to query devices.
23
24
@@ -88,6 +89,7 @@ The query syntax is similar to SQL syntax and is made up of the following clause
88
89
-`FROM` is required and identifies the device type you're querying. This clause specifies the device template ID.
89
90
-`WHERE` is optional and lets you filter the results.
90
91
-`ORDER BY` is optional and lets you sort the results.
92
+
-`GROUP BY` is optional and lets you aggregate results.
91
93
92
94
The following sections describe these clauses in more detail.
93
95
@@ -118,8 +120,8 @@ You can find the component name in the device template:
118
120
The following limits apply in the `SELECT` clause:
119
121
120
122
- There's no wildcard operator.
121
-
- You can't have more than five items in the select list.
122
-
- In a single query, you either select telemetry or properties but not both.
123
+
- You can't have more than 15 items in the select list.
124
+
- In a single query, you either select telemetry or properties but not both. A property query can include both reported properties and cloud properties.
123
125
124
126
### Aliases
125
127
@@ -131,6 +133,9 @@ Use the `AS` keyword to define an alias for an item in the `SELECT` clause. The
131
133
}
132
134
```
133
135
136
+
> [!TIP]
137
+
> You can't use another item in the select list as an alias. For example, the following isn't allowed `SELECT id, temp AS id...`.
138
+
134
139
The result looks like the following output:
135
140
136
141
```json
@@ -224,10 +229,9 @@ The following operators are supported:
224
229
225
230
The following limits apply in the `WHERE` clause:
226
231
227
-
- You can use a maximum of three operators in a single query.
232
+
- You can use a maximum of 10 operators in a single query.
228
233
- In a telemetry query, the `WHERE` clause can only contain telemetry and device metadata filters.
229
-
- In a property query, the `WHERE` clause can only contain property and device metadata filters.
230
-
- Data type validation isn't supported. The comparison value must match the capability schema type.
234
+
- In a property query, the `WHERE` clause can only contain reported properties, cloud properties, and device metadata filters.
231
235
232
236
## Aggregations and GROUP BY clause
233
237
@@ -263,14 +267,12 @@ The results look like the following output:
263
267
}
264
268
```
265
269
266
-
The following aggregation functions are supported: `MAX`, `MIN`, `COUNT`, `AVG`, `FIRST`, and `LAST`.
270
+
The following aggregation functions are supported: `SUM`, `MAX`, `MIN`, `COUNT`, `AVG`, `FIRST`, and `LAST`.
267
271
268
272
Use `GROUP BY WINDOW` to specify the window size. If you don't use `GROUP BY WINDOW`, the query aggregates the telemetry over the last 30 days.
269
273
270
-
The following limits apply to the use of aggregates:
271
-
272
-
- You can only aggregate telemetry values.
273
-
- You can't use multiple aggregations on the same value. For example `LAST(temp), AVG(temp)` isn't supported.
274
+
> [!NOTE]
275
+
> You can only aggregate telemetry values.
274
276
275
277
## ORDER BY clause
276
278
@@ -285,8 +287,16 @@ The `ORDER BY` clause lets you sort the query results by a telemetry value, the
285
287
> [!TIP]
286
288
> Combine `ORDER BY` with `TOP` to limit the number of results the query returns after sorting.
287
289
288
-
`ORDER BY` isn't supported in property queries.
290
+
## Limits
291
+
292
+
The current limits for queries are:
293
+
294
+
- No more than 15 items in the `SELECT` clause list.
295
+
- No more than 10 logical operations in the `WHERE` clause.
296
+
- Queries return a maximum of 10,000 records.
297
+
- The maximum length of a query string is 350 characters.
298
+
- You can't use the wildcard (`*`) in the `SELECT` clause list.
289
299
290
300
## Next steps
291
301
292
-
Now that you've learned how to query devices with the REST API, a suggested next step is to [How to use the IoT Central REST API to manage users and roles](howto-manage-users-roles-with-rest-api.md).
302
+
Now that you've learned how to query devices with the REST API, a suggested next step is to learn [How to use the IoT Central REST API to manage users and roles](howto-manage-users-roles-with-rest-api.md).
0 commit comments