Batch Associate Asset


将指定已有资产节点批量关联到资产树上。待关联的资产可以是设备资产,也可以是逻辑资产。如果待关联的资产节点是一个设备资产,可使用设备资产的 product key、 device key 或者 asset ID 来描述,如果待关联的资产节点是一个逻辑资产,可使用逻辑资产的 ID 来描述。

操作权限

需授权的资源 所需操作权限
资产树 Full Access

请求格式

POST https://{apigw-address}/asset-tree-service/v2.1/asset-nodes?action=associateAssetBatch

请求参数(URI)

名称 位置(Path/Query) 必需/可选 数据类型 描述
orgId Query 必需 String 资产所属的组织 ID。如何获取 orgId 信息>>
treeId Query 必需 String 需要获取的资产树 ID。如何获取资产树信息 ID>>
parentAssetId Query 必需 String 待关联资产的父资产 ID。

请求参数(Body)

名称 必需/可选 数据类型 描述
assetIdentifiers 必需 AssetIdentifiersVo 结构体数组 资产的信息。其结构参见 AssetIdentifiersVo 结构体

AssetIdentifiersVo 结构体

注解

以下非必须字段中,必须提供 assetIdproductKey + deviceKey 的组合,用于指定设备。

名称 必需/可选 数据类型 描述
assetId 可选 String 资产 ID。如何获取 assetId 信息>>
productKey 可选 String 设备的 product key,需与 deviceKey 一起使用。
deviceKey 可选 String 设备的 device key,需与 productKey 一起使用。

响应参数

名称 数据类型 描述
data EnosBatchEachData 结构体数组 成功或失败消息列表。有关 EnosBatchEachData 结构体的定义,参见 EnosBatchEachData 结构体
successSize Integer 成功关联数。
totalSize Integer 需要关联总数。

EnosBatchEachData 结构体

名称 数据类型 描述
code Integer 更新成功或失败的指示码。成功时返回 0;如果返回其他值,则为失败。
msg String 成功时返回 OK;如果返回其他值,则为失败。
data String 若创建成功,则为 assetId

错误码

代码 错误信息 描述
17752 Parent assetId is not existed in the tree 父资产不存在该树上。
17758 AssetId is existed in the tree Asset ID 已存在。
17762 The tree is locked 一次只允许一个用户修改资产树,暂时不能操作该资产树,请再次请求。
17770 Exceeding the layer limit(7) 该树超过最高层数限制(7层)。
99400 Invalid arguments 请求参数非法,请检查请求参数。
99404 TreeId is not exist Tree ID 不存在。
99500 System error 服务器内部错误,请联系 EnOS。

示例

请求示例

url: https://{apigw-address}/asset-tree-service/v2.1/asset-nodes?action=associateAssetBatch&orgId=yourOrgId&treeId=yourTreeId&parentAssetId=yourParentAssetId
method: POST
requestBody:
{
  "assetIdentifiers": [
    {
      "assetId": "assetId1"
    },
    {
      "deviceKey": "yourDeviceKey",
      "productKey": "yourProductKey"
    }
  ]
}

返回示例

{
  "code":99206,
  "msg":"Partial Content Success",
  "requestId":"deb2cf9d-b512-456f-b046-30e365c54e9c",
  "data":[
      {
          "code":758,
          "msg":"asset is existed in the tree.",
          "data":"assetId1"
      },
      {
          "code":0,
          "msg":"OK",
          "data":"assetId2"
      }
  ],
  "successSize":1,
  "totalSize":2
}

SDK 示例


你可以在 Github 上获取资产树服务 API 的 SDK 示例: