Azure IoT中心-批量创建或更新REST API返回错误 [英] Azure IoT Hub - Bulk Create or Update REST API returns error
问题描述
我正在尝试使用预览版Azure IoT中心API来在REST调用中创建多个设备(批量). API不断返回
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:
主机 https://<hub-name>.azure-devices.net/devices?api-version=2019-07-01-preview
标题 Authorization: valid-sas-token-(tested this one), Content-Type: application/json
身体
{
"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"
}
}
]
}
这是我收到的回复
{
"Message": "ErrorCode:ArgumentInvalid;Request does not contain any devices",
"ExceptionMessage": "Tracking ID:2406c2332a83409aa73403d27c2f6083-G:4-TimeStamp:11/26/2019 03:10:17"
}
我已经测试了SAS令牌,并且可以向IoT中心发送和接收消息.任何帮助,将不胜感激.
I have tested the SAS token and I can send and receive messages fine to the IoT Hub. Any help would be appreciated.
推荐答案
文档不正确,请尝试以下操作:
The document is not correct, try the following:
[
{
"id":"TD_00000001",
"importMode":"create",
"status":"enabled"
},
{
"id":"TD_00000002",
"importMode":"create",
"status":"enabled"
}
]
您应该收到以下回复:
{
"isSuccessful":true,
"errors":[],
"warnings":[]
}
这篇关于Azure IoT中心-批量创建或更新REST API返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!