Search code examples
azureazure-iot-hub-device-management

Device Twin IoT Hub - get tags from JSON in python


I have a question. I would like to get "tags" from JSON from my device twin in IoT Hub. I'm trying to do this with IoTHubRegistryManager:

iothub_registry_manager = IoTHubRegistryManager(CONNECTION_STRING)
iothub_registry_manager.get_device(name)

but I will receive like that only partially JSON with:

additional_properties
device_id
generation_id
etag
connection_state

and so on but I can not see the "tags" key which is the most important for me. Do you have maybe some suggestions on how I can get this from python?

Thank you in advance


Solution

  • You want to call get_twin instead of get_device, e.g.

    twin = iothub_registry_manager.get_twin(name)
    

    You will notice that the Twin model in the source code and documentation returns a Twin object which has a tags property, unlike the Device object which does not.