No device connection string in IoT Hub

Innov8 15 Reputation points

We are building in the functionality to send cloud to device messages to trigger actions on device remotely. We are actually looking for how to create the device connection string programmatically, but when we check in IoT hub none of our devices have connection strings.

The following documentation states that they can be found on the device page in IoT hub resource in Azure, but they are not present. User's image

We actually need the information on how to recreate the connection string in PHP, but also would like to know why they do not exist in Azure?

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

2 answers

Sort by: Most helpful
  1. Sander van de Velde 27,051 Reputation points MVP

    Hello @Innov8,

    welcome to this moderated Azure community forum.

    This is weird, normally, the connection strings (primary/secundary) are shown next to the two keys.

    I just created this test device in the West Europe region (with autogenerated symmetric keys in the Azure portal):

    User's image

    How did you create this device? Using the Azure portal? Or using some script? If so, Can you share it?

    A connection string is not that special:

    HostName=[name of iot hub];DeviceId=[device name];SharedAccessKey=[one of the two keys]

    But... it is strongly recommended to make use the Device Provisioning Service to control future IoT Hub selection/migration. This way, you do not need to access all your device to migrate to another IoT Hub.

    Next to that, for Cloud to Device communication like a Direct Method call, you need to have the IoT Hub connectionstring!

    See also this example in the documentation.

    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

  2. Dom 1,466 Reputation points Microsoft Employee

    It looks like your device is configured to authenticate using an X.509 certificate rather than a shared access key - this is why your screenshot is showing thumbprints and not keys/connection-strings.

    The connection string for a device that uses X.509 authentication looks like:


    I notice as well that you're trying to send a cloud to device message - the device connection string is only for devices to connect to your hub. If you want to connect to your hub from a back-end service in order to send a cloud to device message, you need to use the IoT hub connection string - this is described further on in the article you were looking at here: After your back-end service connects to IoT Hub, it just needs the device ID to send a C2D message.