Post Command

Attempts to send a synchronous command to a listening device and returns back when the device acknowledges the command

Azure IoT Hub Command Documentation

URL

https://{{HOST}}/transport/devices/{deviceId}/command

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/command' 
  -H 'Authorization: Bearer {access_token}' 
  -H 'Content-Type: application/json' 
  -d '{
  "type": "echo",
  "timeout": 30,
  "data": {
    "msg": "Hello World!",
    "times": 4
  }
}'

Response

{
    "id":"e6620796-b318-4bae-b0af-8720d4d0f3c5",
    "status":"200",
    "payload": {
        "someDeviceProperty": "itwantstosendback"
    }
}

Response Body Parameters

Name Description Schema
id A unique identifier representing the request
status The status code representing the response
payload Dictionary object with keys and values sent back from the device

Errors

Error Description
401 Unauthorized
403 You do not have access to this device
You do not have access to this endpoint (scope)
404 Device not found or not connected
504 Device received the command, but did not acknowledge within the timeout