question

JustinPham-4634 avatar image
0 Votes"
JustinPham-4634 asked MatthijsvdVeer answered

Request Example for Azure IoT Hub REST API query

I want to query the Azure IoT hub through a the query endpoint using an http request. Currently I am receiving a Internal Server Error with the following request through Postman:

https://{iothubname.etc}/devices/query?api-version=2020-05-31-preview
with a request body containing {query: "SELECT * FROM devices"}

Directly querying the hub with the query works so I believe that it is valid and other requests are authenticating properly so I am believe that it is a problem with how I am formatting my request.

Can someone point out which part of my requests is causing the issue or provide a working example with the same endpoint?

Thanks!

Note: The documentation for the request can be found here https://docs.microsoft.com/en-us/rest/api/iothub/service/query/get-twins

azure-iot-hub
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MatthijsvdVeer avatar image
0 Votes"
MatthijsvdVeer answered

Make sure to set the content type of the body to JSON. If it's not set to the correct content type, you will get an internal server error.
196214-image.png

While it won't result in an error, you should also write "query" with double-quotes. The above will work, but Postman will tell you it's not technically valid JSON.


image.png (59.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.