绑定设备策略
功能介绍
应用服务器可调用此接口在物联网平台上为批量设备绑定目标策略,目前支持绑定目标类型为:设备、产品,当目标类型为产品时,该产品下所有设备都会生效。
调试
您可以在API Explorer中调试该接口,支持自动认证鉴权。API Explorer可以自动生成SDK代码示例,并提供SDK代码示例调试功能。
URI
POST /v5/iot/{project_id}/device-policies/{policy_id}/bind
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
project_id |
是 |
String |
参数说明:项目ID。获取方法请参见 获取项目ID。 |
|
policy_id |
是 |
String |
策略ID |
请求参数
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
Instance-Id |
否 |
String |
参数说明:实例ID。物理多租下各实例的唯一标识,建议携带该参数,在使用专业版时必须携带该参数。您可以在IoTDA管理控制台界面,选择左侧导航栏“总览”页签查看当前实例的ID,具体获取方式请参考 查看实例详情。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
target_type |
是 |
String |
参数说明:策略绑定的目标类型。 取值范围:device|product|app,device表示设备,product表示产品,app表示整个资源空间。 |
|
target_ids |
是 |
Array of strings |
策略绑定的目标ID列表 |
响应参数
状态码:200
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
policy_id |
String |
策略ID。 |
|
target_type |
String |
参数说明:策略的目标类型。 取值范围:device|product|app,device表示设备,product表示产品,app表示整个资源空间。 |
|
success_targets |
Array of strings |
成功的目标id列表。 |
|
failure_targets |
Array of DevicePolicyBindOrUnbindFailureDetail objects |
失败的目标id列表 |
请求示例
-
为设备绑定策略
POST https://{endpoint}/v5/iot/{project_id}/device-policies/{policy_id}/bind { "target_type" : "device", "target_ids" : [ "64a7ba7ef9cb063d27e16b97_123456", "64a7ba7ef9cb063d27e16b97_123457" ] } -
为产品绑定策略
POST https://{endpoint}/v5/iot/{project_id}/device-policies/{policy_id}/bind { "target_type" : "product", "target_ids" : [ "64a7ba7ef9cb063d27e16b97" ] }
响应示例
状态码:200
OK
{
"policy_id" : "5c90fa7d3c4e4405e8525079",
"target_type" : "device",
"success_targets" : [ "64a7ba7ef9cb063d27e16b97_123456", "64a7ba7ef9cb063d27e16b97_123457" ],
"failure_targets" : [ {
"target_id" : "64a7ba7ef9cb063d27e16b97_123458",
"error_code" : "IOTDA.015204",
"error_msg" : "Operation not allowed. The number of policies bound to the target reaches the upper limit (5)."
} ]
}
状态码
|
状态码 |
描述 |
|---|---|
|
200 |
OK |
|
400 |
Bad Request |
|
401 |
Unauthorized |
|
403 |
Forbidden |
|
404 |
Not Found |
|
500 |
Internal Server Error |
错误码
请参见错误码。