Asset Management Client for Node.js¶
Introduction¶
The Asset Management Node.js client allows you to interact with the digital representation of a machine or automation system. Refer to Asset Management for more information about the service.
Further implementation of the AgentManagement SDK library has been shown in a sample project that you can download and test in local or on Industrial IoT application. Please refer to this repository: industrial-iot-node-sdk-examples
Hint
Placeholders in the following samples are indicated by angle brackets < >
.
Aspect Type Operations¶
The aspect type client manages static and dynamic aspect types. It lists, creates, updates, reads and deletes aspect types.
Client name: AspecttypeClient
List all Aspect Types¶
Get all aspect types of the tenant.
// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;
// Require AspecttypeClient from assetmanagement-sdk module
const AspecttypeClient = require('assetmanagement-sdk').AspecttypeClient;
// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();
// Construct the AspecttypeClient object
let aspect_type_client = new AspecttypeClient(config, credentials);
let aspect_types = null;
try {
let request_object = {
page: <page>,
size: <size>,
sort: <sort>,
filter: <filter>,
ifNoneMatch: <ifNoneMatch>
};
aspect_types = await aspect_type_client.listAspectTypes(request_object);
}catch (ex) {
// Exception handling
}
Create an Aspect Type¶
Create an aspect type.
// Construct the AspecttypeClient object as shown above
let aspect_type_input = {
name: <aspect_name>,
category: 'dynamic',
scope: 'private',
description: '<Aspect Type description>',
variables: [
{
name: 'Temperature',
dataType: 'STRING',
unit: 'C',
searchable: true,
length: 3,
qualityCode: true
}
]
};
let aspect_type = null;
try {
const request_object = {
id: <id>,
aspecttype: aspect_type_input
};
aspectType = await aspect_type_client.saveAspectType(request_object);
} catch (ex) {
// Exception handling
}
Update an Aspect Type¶
Update an existing aspect type. Variables can only be added, but not removed or renamed.
// Construct the AspecttypeClient object as shown above
let aspect_type = null;
try {
const request_object = {
id: <id>,
aspecttype: <updated_aspect_type>,
ifMatch: <ifMatch>
};
aspect_type = await aspect_type_client.saveAspectType(request_object);
} catch (ex) {
// Exception handling
}
Read an Aspect Type¶
Read an aspect type with the user defined aspect type ID.
// Construct the AspecttypeClient object as shown above
let aspect_type_resource = null;
try {
let request_object = {
id: <id>,
ifNoneMatch: <ifNoneMatch>
};
aspect_type_resource = await aspect_type_client.getAspectType(request_object);
} catch (ex) {
// Exception handling
}
Delete an Aspect Type¶
Delete an aspect type. An aspect type can only be deleted, if no asset type uses it.
// Construct the AspecttypeClient object as shown above
try {
let request_object = {
id: <id>,
ifMatch: <ifMatch>
};
await aspect_type_client.deleteAspectType(request_object);
} catch (ex) {
// Exception handling
}
Asset Type Operations¶
The asset type client manages asset types. It lists, creates, updates, reads and deletes asset types. It can also be used to add and delete file assignments to asset types.
Client name: AssettypeClient
List all Asset Types¶
List all asset types of the tenant.
// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;
// Require AssettypeClient from assetmanagement-sdk module
const AssettypeClient = require('assetmanagement-sdk').AssettypeClient;
// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();
// Construct the AssettypeClient object
let asset_type_client = new AssettypeClient(config, credentials);
let asset_types = null;
try {
const request_object = {
page: <page>,
size: <size>,
sort: <sort>,
filter: <filter>,
ifNoneMatch: <ifNoneMatch>,
exploded: <exploded>
};
asset_types = await asset_type_client.listAssetTypes(request_object);
} catch (ex) {
// Exception handling
}
Create an Asset Type¶
Create an asset type.
// Construct the AssettypeClient object as shown above
let asset_type_resource = null;
try {
const request_object = {
id: <id>,
assettype: <asset_type>
};
asset_type_resource = await asset_type_client.saveAssetType(request_object);
} catch (ex) {
// Exception handling
}
Update an Asset Type¶
Update an existing asset type.
// Construct the AssettypeClient object as shown above
let asset_type_resource = null;
try {
const request_object = {
id: <id>,
assettype: <asset_type>,
ifMatch: <ifMatch>
};
asset_type_resource = await asset_type_client.updateAssetType(request_object);
} catch (ex) {
// Exception handling
}
Read an Asset Type¶
Read an asset type.
// Construct the AssettypeClient object as shown above
let asset_type_resource = null;
try {
const request_object = {
id: <id>,
ifNoneMatch: <ifNoneMatch>,
exploded: <exploded>
};
asset_type_resource = await asset_type_client.getAssetType(request_object);
} catch (ex) {
// Exception handling
}
Delete an Asset Type¶
Delete an asset type. Deletion is only possible for asset types without children and when there is no asset instantiating them.
// Construct the AssettypeClient object as shown above
try {
const request_object = {
id: <id>,
ifMatch: <ifMatch>
};
await asset_type_client.deleteAssetType(request_object);
} catch (ex) {
// Exception handling
}
Add a New File Assignment to an Asset Type¶
Add a new file assignment to an asset type. By default, this file is assigned to asset types which extend this type and assets instantiated from it.
// Construct the AssettypeClient object as shown above
let asset_type_resource = null;
try {
const request_object = {
ifMatch: <ifMatch>,
id: <id>,
key: <key>,
assignment: <file_id_to_be_assigned>
};
asset_type_resource = await asset_type_client.saveAssetTypeFileAssignment(request_object);
} catch (ex) {
// Exception handling
}
Delete a File Assignment from an Asset Type¶
Deletes a file assignment from an asset type. If the file is assigned to the type's parent, its key will be displayed in the inherited value field.
// Construct the AssettypeClient object as shown above
let asset_type_resource = null;
try {
const request_object = {
id: <id>,
key: <key>,
ifMatch: <ifMatch>
};
asset_type_resource = await asset_type_client.deleteAssetTypeFileAssignment(request_object);
} catch (ex) {
// Exception handling
}
Asset Operations¶
The asset client manages the user's assets and their locations. Three different types of assets can be created: device types, agent types and hierarchy types. The asset client lists, creates, updates, reads, deletes, moves and replaces assets. It can also be used to add and delete file assignments to assets.
Client name: AssetsClient
List all Assets¶
List all assets available for the authenticated user.
// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;
// Require AssetsClient from assetmanagement-sdk module
const AssetsClient = require('assetmanagement-sdk').AssetsClient;
// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();
// Construct the AssetsClient object
let assets_client = new AssetsClient(config, credentials);
let assets = null;
try{
const request_object = {
page: <page>,
size: <size>,
sort: <sort>,
filter: <filter>,
ifNoneMatch: <ifNoneMatch>
};
assets = await assets_client.listAssets(request_object);
} catch (ex) {
// Exception handling
}
Create an Asset¶
Create a new asset with the provided content.
// Construct the AssetsClient object as shown above
let asset_resource = null;
try{
const request_object = {
asset: <asset>
};
asset_resource = await assets_client.addAsset(request_object);
} catch (ex) {
// Exception handling
}
Read an Asset¶
Read an asset. All static properties of the asset are returned.
// Construct the AssetsClient object as shown above
let asset_resource = null;
try{
const request_object = {
id: <id>,
ifNoneMatch: <ifNoneMatch>
};
asset_resource = await assets_client.getAsset(request_object);
} catch (ex) {
// Exception handling
}
Update an Asset¶
Update an existing asset with the provided content. Only values can be modified, but not the asset structure. The asset structure can be modified in the asset type.
// Construct the AssetsClient object as shown above
let asset_resource = null;
try{
const request_object = {
ifMatch: <ifMatch>,
id: <id>,
asset: <asset_update>
};
const asset_resource = await assets_client.updateAsset(request_object);
} catch (ex) {
// Exception handling
}
Delete an Asset¶
Delete an existing asset. After deletion, users with an admin role can still read the asset, but modification is not possible anymore. It is not possible to delete an asset if it has children.
// Construct the AssetsClient object as shown above
try{
const request_object = {
ifMatch: <ifMatch>,
id: <id>
};
await assets_client.deleteAsset(request_object);
} catch (ex) {
// Exception handling
}
Move an Asset¶
Move an existing asset and all of its children in the instance hierarchy.
// Construct the AssetsClient object as shown above
let asset_resource = null;
try{
const request_object = {
ifMatch: <ifMatch>,
id: <id>,
moveParameters: <asset_move>
};
asset_resource = await assets_client.moveAsset(request_object);
} catch (ex) {
// Exception handling
}
Replace an Asset¶
Updates an asset with the provided content.
// Construct the AssetsClient object as shown above
let asset_resource = null;
try{
const request_object = {
ifMatch: <ifMatch>,
id: <id>,
asset: <asset_update>
};
asset_resource = await assets_client.replaceAsset(request_object);
} catch (ex) {
// Exception handling
}
Get the User's Root Asset¶
Read the user's root asset, from which the whole asset hierarchy can be rebuilt.
// Construct the AssetsClient object as shown above
let root_asset_resource = null;
try{
const request_object = {
ifNoneMatch: <ifNoneMatch>
};
root_asset_resource = await assets_client.getRootAsset(request_object);
} catch (ex) {
// Exception handling
}
Add a New File Assignment to an Asset¶
Add a new file assignment to an asset. The file is assigned to all children of the asset by default.
// Construct the AssetsClient object as shown above
let asset_resource = null;
try {
const request_object = {
id: <id>,
key: <key>,
ifMatch: <ifMatch>,
assignment: <file_id_to_be_assigned>
};
asset_resource = await assets_client.saveAssetFileAssignment(request_object);
} catch (ex) {
// Exception handling
}
Delete a File Assignment from an Asset¶
Deletes a file assignment from an asset.
// Construct the AssetsClient object as shown above
let asset_resource = null;
try {
const request_object = {
id: <id>,
key: <key>,
ifMatch: <ifMatch>
};
asset_resource = await assets_client.deleteAssetFileAssigment(request_object);
} catch (ex) {
// Exception handling
}
Structure Operations¶
The structure client is used to list an asset's aspects and variables.
Client name: StructureClient
Get an Asset's Variables¶
Get all variables of an asset.
// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;
// Require StructureClient from assetmanagement-sdk module
const StructureClient = require('assetmanagement-sdk').StructureClient;
// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();
// Construct the StructureClient object
let structure_client = new StructureClient(config, credentials);
let structure_variables = null;
try{
const request_object = {
id: <id>,
page: <page>,
size: <size>,
sort: <sort>,
filter: <filter>,
ifNoneMatch: <ifNoneMatch>
};
structure_variables = await structure_client.listAssetVariables(request_object);
} catch (ex) {
// Exception handling
}
Get all Aspects of an Asset¶
Get all static and dynamic aspects of an asset.
// Construct the StructureClient object as shown above
let structure_aspects = null;
try{
const request_object = {
id: <id>,
page: <page>,
size: <size>,
sort: <sort>,
filter: <filter>,
ifNoneMatch: <ifNoneMatch>
};
structure_aspects = await structure_client.listAssetAspects(request_object);
} catch (ex) {
// Exception handling
}
Locations Operations¶
The locations client manages the location of the asset. It can be used to create, update and delete an asset's location.
Client name: LocationsClient
Create or Update an Asset's Location¶
Creates or updates the location that is assigned to an asset. If no location is defined for the asset yet, a new one is created. Otherwise, it is updated.
// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;
// Require LocationsClient from assetmanagement-sdk module
const LocationsClient = require('assetmanagement-sdk').LocationsClient;
// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();
// Construct the LocationsClient object
let locations_client = new LocationsClient(config, credentials);
let updated_asset = null;
try{
const request_object = {
ifMatch: <ifMatch>,
id: <id>,
location: <location>
};
updated_asset = await locations_client.saveAssetLocation(request_object);
} catch (ex) {
// Exception handling
}
Delete an Asset's Location¶
Delete the location from an asset.
// Construct the LocationsClient object as shown above
let updated_asset = null;
try{
const request_object = {
ifMatch: <ifMatch>,
id: <id>
};
updated_asset = await locations_client.deleteAssetLocation(request_object);
} catch (ex) {
// Exception handling
}
Billboard Operations¶
The billboard client can be used to list all available resources.
Client name: BillboardClient
List all Available Resources¶
List all links for available resources.
// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;
// Require BillboardClient from assetmanagement-sdk module
const BillboardClient = require('assetmanagement-sdk').BillboardClient;
// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();
// Construct the BillboardClient object
let billboard_client = new BillboardClient(config, credentials);
let billboard_resource = null;
try{
billboard_resource = await billboard_client.getBillboard();
} catch (ex) {
// Exception handling
}
File Operations¶
The files client manages files that can be assigned to a resource. It is used to list, read, upload, delete, replace and download a file.
Client name: FilesClient
List all Files¶
Get metadata of all uploaded files.
// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;
// Require FilesClient from assetmanagement-sdk module
const FilesClient = require('assetmanagement-sdk').FilesClient;
// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();
// Construct the FilesClient object
let files_client = new FilesClient(config, credentials);
let file_metadata_list_resource = null;
try{
const request_object = {
page: <page>,
size: <size>,
sort: <sort>,
filter: <filter>,
ifNoneMatch: <ifNoneMatch>
};
file_metadata_list_resource = await files_client.listFiles(request_object);
} catch (ex) {
// Exception handling
}
Get a File¶
Get the metadata of a file with the user defined ID.
// Construct the FilesClient object as shown above
let file_metadata_list_resource = null;
try{
const request_object = {
fileId: <file_id>,
ifNoneMatch: <ifNoneMatch>
};
file_metadata_list_resource = await files_client.getFile(requestObject);
} catch (ex) {
// Exception handling
}
Download a File¶
Returns the file with the user defined ID.
// Construct the FilesClient object as shown above
let file_content = null;
try{
const request_object = {
fileId: <file_id>
};
file_content = await files_client.downloadFile(request_object);
} catch (ex) {
// Exception handling
}
Replace a File¶
Update a previously uploaded file. The maximum file size is 5Â MB.
// Construct the FilesClient object as shown above
let file_metadata_resource = null;
try{
const request_object = {
ifMatch: <ifMatch>,
fileId: <file_id>,
file: <file>,
name: <name>,
scope: <scope>,
description: <description>
};
file_metadata_resource = await files_client.replaceFile(request_object);
} catch (ex) {
// Exception handling
}
Upload a File¶
Upload a file to be used in Asset Management.
// Construct the FilesClient object as shown above
let file_metadata_resource = null;
try{
const request_object = {
file: <file>,
name: <name>,
scope: <scope>,
description: <description>
};
file_metadata_resource = await files_client.uploadFile(request_object);
} catch (ex) {
// Exception handling
}
Delete a File¶
// Construct the FilesClient object as shown above
try{
const request_object = {
ifMatch: <ifMatch>,
fileId: <file_id>
};
await files_client.deleteFile(request_object);
} catch (ex) {
// Exception handling
}