Azure IoT send cloud to device message using an API

Julian Werfel 0 Reputation points
2023-03-06T16:56:07.47+00:00

I am trying to send a cloud to device message using Azure IoT - is there an existing REST API for this functionality? I want to do the same capability in the C# SDK however I want to use an API rather than an SDK. I have not found documentation for cloud to device messaging - does it exist?

This would be equivalent to the Microsoft.Azure.Devices.ServiceClient.SendAsync() method

Thank you

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

2 answers

Sort by: Most helpful
  1. Sander van de Velde | MVP 36,761 Reputation points MVP Volunteer Moderator
    2023-03-06T20:14:27.15+00:00

    Hello @Julian Werfel ,

    unfortunately, there is no REST API support for sending cloud messages to devices.

    The related REST API only supports manipulating the queue in which cloud messages are stored within the IoT Hub (for each device separately).

    It's recommended to leave the logic manipulating the IoT Hub within so the cloud so the IoT Hub secrets are not exposed outside the Azure cloud.

    So, I recommend using the SDK and wrapping the SDK logic in an Azure Function with an HTTP trigger and still making use of HTTP.


    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.

    0 comments No comments

  2. QuantumCache 20,366 Reputation points Moderator
    2023-03-06T21:56:24.1266667+00:00

    Hello @Julian Werfel Thanks for the query on this forum!

    Could you please add more info on your Use-Case or scenario on the need for API to send Cloud to Device messages via REST API instead of SDK? any backend application limitations in your project, to use SDK?
    Diagram showing the list of build-in IoT Hub endpoints.

    Send cloud-to-device messages from an IoT hub

    IoT Hub provides three options for device apps to expose functionality to a back-end app:

    • Direct methods for communications that require immediate confirmation of the result. Direct methods are often used for interactive control of devices such as turning on a fan.
    • Twin's desired properties for long-running commands intended to put the device into a certain desired state. For example, set the telemetry send interval to 30 minutes.
    • Cloud-to-device messages for one-way notifications to the device app.

    Device endpoints. For each device in the identity registry, IoT Hub exposes a set of endpoints, These endpoints are used by the device to Pull the related data.

    Service endpoints. Each IoT hub exposes a set of endpoints for your solution back end to communicate with your devices.

    If you are trying to send a Cloud-To-Device Message using the REST API directly you can't by-design, As Azure IoThub stands like a guardian protecting large scale of devices.

    I would recommend to give a try with Direct-Methods!, as i have seen many projects using Direct Methods for various purpose (You can be creative here!!) even though your scenario may be different, we certainly can help you over here...!

    Anyone with service connect permissions on IoT Hub may invoke a method on a device.

    Direct methods follow a request-response pattern and are meant for communications that require immediate confirmation of their result. For example, interactive control of the device, such as turning on a fan. Yes, you can also write a wrapper using Azure Functions using SDK, as per Sander's suggestion on this thread!!!


    If this answers your query, do click Accept Answer and Yes for this answer as helpful. And, if you have any further query do let us know by commenting in the below section.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.