I'm trying to send a message to my device from the cloud, using Azure IoT Hub and REST api (not using the Azure IoT hub python SDK).
I can successfully send a message (POST request) to the hub from the device with uri https://<myiothub>.azure-devices.net/devices/<devid>/messages/events?api-version=2018-06-30
. In the documentation at https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-messages-c2d it says there is a service-side endpoint at /messages/devicebound
. However, they don't show a complete example, so I'm not entirely sure what the full endpoint I should use is, and how/where to specify which device to send to.
I anyway tried the following:
curl -v POST \
https://<myhub>.azure-devices.net/messages/devicebound?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas>' \
-H 'Content-Type: application/json' \
-d '{
"payload": {
"key": "value"
}
}'
where is generated via Azure CLI az iot hub generate-sas-token -n <myhub>
. I get the error message
{"Message":"ErrorCode:ArgumentInvalid;Request must contain IoTHub custom 'To' header","ExceptionMessage":"Tracking ID:ec98ff8...
where I cut off the end. So I tried adding a "To" header, which regardless of what I put returns the same error message.
I also tried what's suggested here Cloud-to-device Azure IoT REST API, namely to send via endpoint https://main.iothub.ext.azure.com/api/Service/SendMessage/, but without luck.