Create and Associate Asset


Create an asset and link it to an asset tree.

Operation Permissions

Required Authorization

Required Operation Permission

Asset Tree

Full Access

Request Format

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

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

asset

Mandatory

Asset Struct

The asset details to be provided when creating an asset. For more information, see Asset Struct

Asset Struct

Name

Mandatory/Optional

Data Type

Description

modelId

Mandatory

String

The model ID which the asset belongs to. 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>>

Response Parameters

Name

Data Type

Description

data

String

The ID of the created asset.

Error Codes

Code

Message

Description

17404

TreeId is not exist

The tree ID does not exist.

17752

Parent assetId is not existed in the tree

The parent asset does not exist in this 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.

99500

System error

Internal server error. Contact EnOS support.

Samples

Request Sample

url: https://{apigw-address}/asset-tree-service/v2.1/asset-nodes?action=createAsset&treeId=yourTreeId&parentAssetId=yourParentAssetId&orgId=yourOrgId
method: POST
requestBody:
{
    "asset": {
        "modelId": "STRING-INVERTER-MODEL",
        "name": {
            "defaultValue": "逆变器 #1",
            "i18nValue": {
                "en_US": "Inverter #1"
            }
        },
        "timezone": "+08:00",
        "description": "This is a sample asset.",
        "attributes": {
            "foo": 100,
            "bar": "example"
        },
        "tags": {
            "foo": "bar",
            "hello": "world"
        }
    }
}

Return Sample

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

SDK Samples


You can access the SDK samples for Asset Tree Service on GitHub: