1

I'd like to be able to pull an IoT Edge device's module twin via an HTTPS GET request just like the Azure Portal does. In the portal, I see this firing...

https://my-hub.azure-devices.net/twins/my-device/modules/my-module?api-version=2020-09-30&_=164130947416

...and returning JSON. I'd like to do the same outside of the portal (like in Postman or something).

Obviously, by being logged in to the portal, I have credentials that permit that.

I've tried creating a Shared Access Signature and using it as a header like so...

"Authorization": "SharedAccessSignature sr=my-hub.azure-devices.net&sig=...

...but I get back ErrorCode:IotHubUnauthorizedAccess;Unauthorized

Am I missing something? Maybe a step where I use that SAS to get some additional credential or something?

Or maybe I can't create a SAS that works with any device-id?

In the end, I'd just like to be able to GET the reported properties for a module twin from any of my IoT Hub devices. No setting, no subscribing.

papakpmartin
  • 193
  • 9

1 Answers1

0

The API you're referring to is documented here. You're doing the right thing, but perhaps your method of creating a Shared Access Signature isn't working. One easy way to create a valid SAS token is by using the az cli command: az iot hub generate-sas-token -n <iot-hub-name>. By default it will create a token for the iothubowner policy, which should give you access to the module twin.

I used Postman, with the Authorization header as you mentioned to check the twin of my device $edgeHub module:

https://<my-iot-hub>.azure-devices.net/twins/<device-id>/modules/$edgeHub?api-version=2020-05-31-preview
Matthijs van der Veer
  • 3,865
  • 2
  • 12
  • 22
  • 1
    I had Postman set up incorrectly. Dropped to `curl` and it all became clear. :) Thanks for the reply, @matthijs-van-der-veer ... it helped me know that it _should_ work! – papakpmartin Jan 04 '22 at 18:17