Associate Asset

将指定已有资产节点关联到资产树上。待关联的资产可以是一个设备资产,也可以是一个逻辑资产。如果待关联的资产节点是一个设备资产,可使用设备资产的Product Key、 Device Key来描述,如果待关联的资产节点是一个逻辑资产,可使用逻辑资产的ID来描述。

操作权限

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

请求格式

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

请求参数(URI)

注解

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

名称 位置(Path/Query) 必需/可选 数据类型 描述
orgId Query 必需 String 资产所属的组织ID。如何获取orgId信息>>
treeId Query 必需 String 需要获取的资产树ID。如何获取资产树信息ID>>
parentAssetId Query 必需 String 待关联资产的父资产ID。
assetId Query 可选 String
待关联的资产ID,如指定 assetId,则关联由 assetId 唯一识别的资产。如何获取Asset ID信息>>
如未指定 assetId,则关联以 productKeydeviceKey 组合唯一识别的资产。
productKey Query 可选 String 待关联设备的Product Key。
deviceKey Query 可选 String 待关联设备的Device Key。

响应参数

名称 数据类型 描述
data String 关联成功的资产ID。

错误码

名称 错误信息 描述
17404 TreeId is not exist Tree ID 不存在。
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 请求参数非法,请检查请求参数。
99500 System error 服务器内部错误,请联系EnOS。

示例

请求示例

url: https://{apigw-address}/asset-tree-service/v2.1/asset-nodes?action=associateAsset&orgId=yourOrgId&treeId=yourTreeId&parentAssetId=yourParentAssetId&productKey=yourProductKey&deviceKey=yourDeviceKey
method: POST

返回示例

{
    "code": 0,
    "msg": "ok",
    "requestId": "01b5477a-374e-49a0-8b68-7dbfe8f0b74f",
    "data": "cRUdS7sJ"
}

Java SDK调用示例

package com.envisioniot.enos.asset_tree_service;

import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envisioniot.enos.asset_tree_service.v2_1.AssociateAssetNodeRequest;
import com.envisioniot.enos.asset_tree_service.v2_1.AssociateAssetNodeResponse;
import org.junit.Test;

public class AssociateAssetNodeTest {
    private static String AccessKey = "yourAccessKey";
    private static String SecretKey = "yourSecretKey";
    private static String OrgId = "yourOrgId";
    private static String ServerUrl = "yourServerUrl";

    @Test
    public void testAssociateAssetNode() {
        AssociateAssetNodeRequest request = new AssociateAssetNodeRequest();
        request.setOrgId(OrgId);
        request.setTreeId("yourTreeId");
        request.setParentAssetId("yourParentAssetId");
        request.setAssetId("yourAssetId");
        AssociateAssetNodeResponse response = Poseidon.config(PConfig.init().appKey(AccessKey).appSecret(SecretKey).debug())
            .url(ServerUrl)
            .getResponse(request, AssociateAssetNodeResponse.class);
    }
}