Request Example for Azure IoT Hub REST API query

Justin Pham 46 Reputation points
2022-04-25T14:00:11.727+00:00

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://learn.microsoft.com/en-us/rest/api/iothub/service/query/get-twins

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,116 questions
0 comments No comments
{count} votes

Accepted answer
  1. Matthijs van der Veer 4,376 Reputation points MVP
    2022-04-25T14:11:01.303+00:00

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful