Skip to content

Asset Management Service – Using Default Values in Asset Types

The following example illustrates how to create an asset type and define default values for one of its properties using the Asset Management Service. Here, an asset type Valve, which has a property named color, is created. A new valve shall be gray by default, but as this example shows, the default value can be overwritten, if required.

Defining Default Values for an Asset Type

Create the asset type using the following request - replace {tenantId} by your tenant's ID:

1
PUT /assettypes/{tenantId}.Valve

Include the following JSON structure in the payload to define the asset type and its default value for the color property:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
{
  "name": "Valve",
  "description": "General purpose valve",
  "parentTypeId": "core.basicdevice",
  "instantiable": true,
  "scope": "private",
  "variables": [
    {
      "name": "color",
      "dataType": "STRING",
      "searchable": true,
      "length": 10,
      "defaultValue": "gray"
    }
  ]
}

Create an asset instance of the newly created asset type using the following request:

1
POST /assets/

Include the following JSON structure in the payload to define the asset - replace {tenantID} by your tenant's ID and {parentAssetId} by the ID of your preferred parent asset:

1
2
3
4
5
6
7
8
{
  "name": "Valve-001",
  "externalId": "SN 123456-123-123456",
  "description": "Valve 001 installed somewhere",
  "typeId": "{tenantId}.Valve",
  "parentId": "{parentAssetId}",
  "timezone": "Europe/Berlin"
}

The response of the call contains the newly created asset instance so you can validate the correct creation:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
  "assetId": "{assetId}",
  "tenantId": "{tenantId}",
  "name": "Valve-001",
  "etag": "{etagValue}",
  "externalId": "SN 123456-123-123456",
  "t2Tenant": null,
  "subTenant": null,
  "description": "Valve 001 installed somewhere",
  "timezone": "Europe/Berlin",
  "parentId": "{parentAssetId}",
  "typeId": "{tenantId}.Valve",
  "location": null,
  "fileAssignments": [],
  "variables": [
    {
      "name": "color",
      "value": "gray"
    }
  ],
  "aspects": [],
  "locks": [],
  "hierarchyPath": [
    {
      "assetId": "{assetId}",
      "name": "{tenantId}"
    }
  ],
  "deleted": null,
  "_links": {
    "self": {
      "href": "{link}"
    },
    "aspects": {
      "href": "{link}"
    },
    "variables": {
      "href": "{link}"
    },
    "location": {
      "href": "{link}"
    },
    "parent": {
      "href": "{link}"
    }
  }
}

The response shows that the color property for Valve-001 is set to gray.

Overwriting the Default Value of an Asset

Change the color property from gray to white using the following request - replace {id} by the asset ID:

1
PATCH /assets/{id}

Provide the {CurrentEtagValue} for the If-Match parameter and the following JSON structure to define the asset:

1
2
3
4
5
6
7
8
{
  "variables": [
    {
      "name": "color",
      "value": "white"
    }
  ]
}

Verify the result in the response body:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
  "assetId": "{assetId}",
  "tenantId": "{tenantId}",
  "name": "Valve-001",
  "etag": "{etagValue}",
  "externalId": "SN 123456-123-123456",
  "t2Tenant": null,
  "subTenant": null,
  "description": "Valve 001 installed somewhere",
  "timezone": "Europe/Berlin",
  "parentId": "{parentAssetId}",
  "typeId": "{tenantId}.Valve",
  "location": null,
  "fileAssignments": [],
  "variables": [
    {
      "name": "color",
      "value": "white"
    }
  ],
  "aspects": [],
  "locks": [],
  "hierarchyPath": [
    {
      "assetId": "{assetId}",
      "name": "{tenantId}"
    }
  ],
  "deleted": null,
  "_links": {
    "self": {
      "href": "{link}"
    },
    "aspects": {
      "href": "{link}"
    },
    "variables": {
      "href": "{link}"
    },
    "location": {
      "href": "{link}"
    },
    "parent": {
      "href": "{link}"
    }
  }
}

Resetting the Default Value of an Asset

When a default property is removed from the instance, it is automatically reset to the default value.

Remove the asset's properties using the following request - replace {id} by the asset ID:

1
PATCH /asset/{id}

Provide the {CurrentEtagValue} for the If-Match parameter and the following JSON structure to define the asset:

1
2
3
4
{
  "variables": [
  ]
}

The return validates that the default value is restored in the asset instance:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
  "assetId": "{assetId}",
  "tenantId": "{tenantId}",
  "name": "Valve-001",
  "etag": "{etagValue}",
  "externalId": "SN 123456-123-123456",
  "t2Tenant": null,
  "subTenant": null,
  "description": "Valve 001 installed somewhere",
  "timezone": "Europe/Berlin",
  "parentId": "{parentAssetId}",
  "typeId": "{tenantId}.Valve",
  "location": null,
  "fileAssignments": [],
  "variables": [
    {
      "name": "color",
      "value": "gray"
    }
  ],
  "aspects": [],
  "locks": [],
  "hierarchyPath": [
    {
      "assetId": "{assetId}",
      "name": "{tenantId}"
    }
  ],
  "deleted": null,
  "_links": {
    "self": {
      "href": "{link}"
    },
    "aspects": {
      "href": "{link}"
    },
    "variables": {
      "href": "{link}"
    },
    "location": {
      "href": "{link}"
    },
    "parent": {
      "href": "{link}"
    }
  }
}

Changing the Default Value of Multiple Assets

You can change the default value of already exisiting assets of the same asset type by updating the asset type. This automatically overwrites the default values of the derived assets.

Use the following request - replace {id} by the {tenantId}.Valve, where {tenantID} is your tenant's ID:

1
PATCH /assettypes/{id}

Provide the {currentEtagValue} for the If-Match parameter and the following JSON structure to define the asset type:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  "variables": [
    {
      "name": "color",
      "dataType": "STRING",
      "searchable": true,
      "length": 10,
      "defaultValue": "black"
    }
  ]
}

Note

You need to add the complete "variables" instance for PATCH.

Use the following request - replace {assetID} by your asset's ID:

1
GET /assets/{assetID}

In the response the color is changed to black:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
  "assetId": "{assetId}",
  "tenantId": "{tenantId}",
  "name": "Valve-001",
  "etag": "{etagValue}",
  "externalId": "SN 123456-123-123456",
  "t2Tenant": null,
  "subTenant": null,
  "description": "Valve 001 installed somewhere",
  "timezone": "Europe/Berlin",
  "parentId": "{parentAssetId}",
  "typeId": "{tenantId}.Valve",
  "location": null,
  "fileAssignments": [],
  "variables": [
    {
      "name": "color",
      "value": "black"
    }
  ],
  "aspects": [],
  "locks": [],
  "hierarchyPath": [
    {
      "assetId": "{assetId}",
      "name": "{tenantId}"
    }
  ],
  "deleted": null,
  "_links": {
    "self": {
      "href": "{link}"
    },
    "aspects": {
      "href": "{link}"
    },
    "variables": {
      "href": "{link}"
    },
    "location": {
      "href": "{link}"
    },
    "parent": {
      "href": "{link}"
    }
  }
}

Finding out the parentID of an Asset

parentId is the ID of the asset one hierarchy level above the actual asset. In the example above the root asset was used as the parent. Inquire the root asset's ID using the following request:

1
GET /assets/root

If the parent is not the root asset then you can see the direct parent of an asset in the `"hierarchyPath" list. It's always the last item in the list. This is also known as "breadcrumbs".

When creating a new asset you need to add the parent asset's ID in the payload. If you do not remember it you can query it using the endpoint shown below and filter for any attribute you know.

1
GET /assets

Any questions left?

Ask the community


Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.