In this article
Post Message
Send an asynchronous message to a device
Azure IoT Hub Message Documentation
URL
https://{{HOST}}/transport/devices/{deviceId}/message
Method
POST
Required IMS Scopes
- device_admin
URL Path Parameters
| Name | Description | Example | Type |
|---|---|---|---|
| deviceId | Id of the device to send command to | /devices/{deviceId} | string |
Request Header Parameters
| Type | Value | Description |
|---|---|---|
| Authentication | Bearer {access_token} required |
Retrieve access token |
| Content-Type required |
application/json | content type |
Request Body Parameters
| Property | Description |
|---|---|
| type | Any string defined by the Application (preferably without spaces / special characters); For COMMANDS: MUST be the name of the registered command handler on the device |
| timeout | Timeout in seconds – used mainly for commands (Direct Methods); If this is not specified, a default of 30 seconds will be used |
| data | Dictionary object with keys and values defined by Application |
Example
Request
curl -X POST
'https://{{HOST}}/transport/devices/testDevice/message'
-H 'Authorization: Bearer {access_token}'
-H 'Content-Type: application/json'
-d '{
"type": "echo",
"timeout": 30,
"data": {
"msg": "f61bfd86-3152-4759-8cac-a89c3e008c7b",
"times": 4
}
}'
Response
[
{
"id":"e6620796-b318-4bae-b0af-8720d4d0f3c5",
"status":"200"
}
]
Response Body Parameters
| Name | Description | Schema |
|---|---|---|
| id | A unique identifier representing the request | |
| status | The status code representing the response |
Errors
| Error | Description |
|---|---|
| 401 | Unauthorized |
| 403 | You do not have access to this device You do not have access to this endpoint (scope) |