Create Asset Tree


Create an asset tree as well as its root node.

Operation Permissions

Required Authorization

Required Operation Permission

Asset Tree Management

Full Access

Request Format

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

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>>

Request Parameters (Body)

Name

Mandatory/Optional

Data Type

Description

asset

Mandatory

Asset Struct

The required data when creating a root node asset. For more details, see Asset Struct.

tree

Optional

TreeCreateVo Struct

The details of the asset tree to be created. For more details, see TreeCreateVo Struct.

Asset Struct

Name

Mandatory/Optional

Data Type

Description

modelID

Mandatory

String

The model ID. How to get modelID>>

name

Mandatory

StringI18n

Specify the asset’s name in its respective locale’s language. For more details on the structure and locales supported, see Internationalized name struct.

timezone

Mandatory

String

  • The timezone where the asset is located.

  • Use the “+08:00” format for time zones that do not support Daylight Saving Time (DST).

  • Use the “Asia/Shanghai” format for time zones that support DST.

For details, see Timezone representation.

description

Optional

String

The asset description.

attributes

Optional

Map

Attributes of the model which the asset belongs to. The Key is the attribute ID, which is of String type. The Value type depends on the attribute defined in the Model. For details, see attributes representation.

tags

Optional

Map

User-defined tags. (The Key and Value are of String type.) For details, see How to use tag.

TreeCreateVo Struct

Name

Mandatory/Optional

Data Type

Description

name

Mandatory

StringI18n

Specify the asset tree’s name in its respective locale’s language. For more details on the structure and locales supported, see Internationalized name struct.

tags

Optional

Map

User-defined tags. (The Key and Value are of String type.) .`How to use tags>> </docs/api/en/2.3.0/api_faqs.html#how-to-use-tag>`_

Response Parameters

Name

Data Type

Description

data

String

The created asset tree ID.

Error Codes

Code

Message

Description

17772

The quota of tree reaches ceiling

Number of trees already reaches maximum of the OU.

99400

Invalid arguments

The request parameter is invalid. Check the request parameters.

99500

System error

Internal server error. Contact EnOS support.

Samples

Request Sample

url: https://{apigw-address}/asset-tree-service/v2.1/asset-trees?action=create&orgId=yourOrgId
method: POST
requestBody:
{
    "asset":{
        "modelId":"modelName",
        "name":{
            "defaultValue":"Name"
        },
        "timezone":"+12:00",
        "description":"Example of description"
    },
    "tree":{
        "name":{
            "defaultValue":"Name"
        }
    }
}

Return Sample

{
  "msg": "OK",
  "code": 0,
  "data": "HfzFPn1H",
  "requestId": "bb4f8c40-604a-451e-83bd-99cfba6bd53e"
}

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.api.common.constant.request.Pagination;
import com.envisioniot.enos.api.common.constant.request.Projection;
import com.envisioniot.enos.asset_tree_service.v2_1.*;
import com.envisioniot.enos.asset_tree_service.vo.*;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;

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

    @Test
    public void testCreateTree() {
        TreeCreateVo tree = new TreeCreateVo();
        I18nVo treeName = new I18nVo();
        treeName.setDefaultValue("treeDefaultName");
        tree.setName(treeName);
        CreateTreeRequest request = new CreateTreeRequest();
        Map < String, String > i18nValue = new HashMap();
        i18nValue.put("zh_CN", "assetName");
        I18nVo name = new I18nVo();
        name.setDefaultValue("assetDefaultName");
        name.setI18nValue(i18nValue);
        AssetCreateVo asset = new AssetCreateVo();
        asset.setModelId("yourModelId");
        asset.setName(name);
        asset.setTimezone("+08:00");
        asset.setDescription("This is a sampled asset");
        request.setTree(tree);
        request.setAsset(asset);
        request.setOrgId(OrgId);
        CreateTreeResponse response = Poseidon.config(PConfig.init().appKey(AccessKey).appSecret(SecretKey).debug())
            .url(ServerUrl)
            .getResponse(request, CreateTreeResponse.class);
    }
}