0
votes

I am trying to use the preview version of the Azure IoT Hub API to create multiple devices (bulk) in a REST call. The API keeps returning

"Request does not contain any devices"

which is weird because I am formatting the request exactly as per the documentation. Here is the details of the call:

Host https://<hub-name>.azure-devices.net/devices?api-version=2019-07-01-preview

Headers Authorization: valid-sas-token-(tested this one), Content-Type: application/json

Body

{ 
   "devices":[ 
      { 
         "id":"TD_00000001",
         "importMode":"create",
         "status":"enabled",
         "authentication":{ 
            "symmetricKey":{ 
               "primaryKey":null,
               "secondaryKey":null
            },
            "x509Thumbprint":{ 
               "primaryThumbprint":null,
               "secondaryThumbprint":null
            },
            "type":"sas"
         }
      },
      { 
         "id":"TD_00000002",
         "importMode":"create",
         "status":"enabled",
         "authentication":{ 
            "symmetricKey":{ 
               "primaryKey":null,
               "secondaryKey":null
            },
            "x509Thumbprint":{ 
               "primaryThumbprint":null,
               "secondaryThumbprint":null
            },
            "type":"sas"
         }
      }
   ]
}

Here is the response that I am receiving

{
    "Message": "ErrorCode:ArgumentInvalid;Request does not contain any devices",
    "ExceptionMessage": "Tracking ID:2406c2332a83409aa73403d27c2f6083-G:4-TimeStamp:11/26/2019 03:10:17"
}

I have tested the SAS token and I can send and receive messages fine to the IoT Hub. Any help would be appreciated.

1

1 Answers

1
votes

The document is not correct, try the following:

[
  {
    "id":"TD_00000001",
    "importMode":"create",
    "status":"enabled"
  },
  {
    "id":"TD_00000002",
    "importMode":"create",
    "status":"enabled"
  }
]

you should received the following response:

{
  "isSuccessful":true,
  "errors":[],
  "warnings":[]
}