Bosch IoT Device Management - will be discontinued by mid 2024

Azure IoT Hub - HTTP connection

Invoke direct methods on Azure IoT Hub devices by sending live messages.

In this example, we configure an HTTP connection that publishes live messages as direct method invocations to Azure IoT Hub.

Table of contents:


To follow this example you will need:

  • A Bosch IoT Things service subscription

  • An Azure IoT Hub instance

  • An Azure IoT Hub device

Create the connection

Starting at the Bosch IoT Suite UI, click the Connection entry in the left navigation.

In case it is not there, use the search, and click the star icon to pin it to your navigation bar.


Please make sure, that your connections are active. This is indicated with the plug symbol: in the example below the first connection is open and will work, the second one is disabled.


If one of your connections are closed, just open them.

  • Click Add to create a new connection.

  • Select HTTP from the categories.

  • Give the connection a name. Setting a name is required.

  • Click the Continue button.


Configure credentials

  • Scroll to the Coordinates section.

  • Choose hmac as the credential type.

  • Choose az-sasl as the algorithm.

  • Click the button Paste Azure IoT Hub connection string.
    Then paste the connection string of a shared access key with the service connect permission.

  • Enter the hostname of your Azure IoT Hub instance <iot-hub-name>


Add a target

  • Scroll to the Targets section.

  • Click the Add target button.

  • Choose POST as the HTTP verb.

  • Enter /twins/{{ thing:id }}/methods?api-version=2018-06-30 as the HTTP path

  • Add an authorization subject, e.g. integration:<solution-id>:aih

  • Check Thing live messages under Topics to publish on address.

  • Click Save new target.


Configure payload mapping

  • Scroll to the Payload mapping section.

  • Check Enable custom JavaScript-based payload mapping

  • Change the outgoing payload mapping to compute the payload for Azure IoT Hub direct method invocation from the subject, payload and timeout of a live message

    function mapFromDittoProtocolMsg(namespace, name, group, channel, criterion,
    action, path, dittoHeaders, value, status, extra) {
    let headers = dittoHeaders;
    let payload = {
    "methodName": action,
    "responseTimeoutInSeconds": parseInt(dittoHeaders.timeout),
    "payload": value
    let textPayload = JSON.stringify(payload);
    let bytePayload = null;
    let contentType = 'application/json';
    return Ditto.buildExternalMsg(headers, textPayload, bytePayload, contentType);
  • Click the Create button at the top right to save the connection.

The connection is ready.

Any live message the connection is authorized to receive is published to Azure IoT Hub as direct method invocation.
Note that the thing ID of the live message should be equal to the device ID in Azure IoT Hub.

Authorize the connection for messages

Follow the steps Add a policy entry for public cloud connections.

Replace xxx from that example with the authorization subject of this connection in the policy, e.g. integration:<solution-id>:aih.