Batch Associate Asset


Batch link existing assets to an asset tree. The assets to be linked can be a device asset or a non-device (logical) asset.

This API is only available if 2.3 Cumulative Update 3 has been applied to your environment. For the full change list of 2.3 Cumulative Update 3, see Cumulative Update 3.

Operation Permissions

Required Authorization Required Operation Permission
Asset Tree Management Full Access

Request Format

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

Request Parameters (URI)

Name Location (Path/Query) Mandatory/Optional Data Type Description
orgId Query Mandatory String The organization ID which the asset belongs to. How to get orgId>>
treeId Query Mandatory String The asset tree ID. How to get treeID>>
parentAssetId Query Mandatory String The asset ID of the parent node of the asset to be linked.

Request Parameters (Body)

Name Mandatory/Optional Data Type Description
assetIdentifiers Mandatory Array of AssetIdentifiersVo Structs The asset information. For more details, see AssetIdentifiersVo Struct.

Response Parameters

Name Data Type Description
data Array of EnosBatchEachData Struct The list of success or failure messages. For more details, see EnosBatchEachData struct.
successSize Integer The number of successfully linked assets.
totalSize Integer The total number of assets to be linked.

Error Codes

Code Message Description
17752 Parent assetId is not existed in the tree The parent asset does not exist in this Tree
17758 AssetId is existed in the tree Asset ID already exists in the tree.
17762 The tree is locked The asset tree cannot be modified/deleted for the time being as someone is currently accessing the asset tree. Please try again later.
17770 Exceeding the layer limit(7) The tree exceeds the maximum number of layers (7 layers).
99400 Invalid arguments The request parameter is invalid. Check the request parameters.
99404 TreeId is not exist The tree ID does not exist.
99500 System error Internal server error. Contact EnOS support.

Samples

Request Sample

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

Return Sample

{
  "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
}

Java SDK Sample

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;

@Test
public void testAssociateAssetNode() {
   AssociateAssetNodeBatchRequest request = new AssociateAssetNodeBatchRequest();
   request.setOrgId(OrgId);
   request.setTreeId("yourTreeId");
   request.setParentAssetId("yourParentAssetId");
   List<AssetIdentifierVo> assetIdentifiersVoList = new ArrayList<>();
   AssetIdentifierVo assetIdentifiersVo1=new AssetIdentifierVo("assetId1");
   assetIdentifiersVoList.add(assetIdentifiersVo1);
   AssetIdentifierVo assetIdentifiersVo2=new AssetIdentifierVo("yourProductKey","yourDeviceKey");
   assetIdentifiersVoList.add(assetIdentifiersVo2);

   request.setAssetIdentifiers(assetIdentifiersVoList);
   AssociateAssetNodeBatchResponse response =
   Poseidon.config(PConfig.init().appKey(AccessKey).appSecret(SecretKey).debug()).url(ServerUrl)
    .getResponse(request, AssociateAssetNodeBatchResponse.class);
    System.out.println(GsonUtil.toJson(response));
}