Azure IoT Hub - Bulk Create or Update REST API returns error

左心房为你撑大大i 提交于 2020-01-25 11:10:11

问题


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:


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":[]
}


来源:https://stackoverflow.com/questions/59043295/azure-iot-hub-bulk-create-or-update-rest-api-returns-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!