Update Asset


Update asset information.

Operation Permissions

Required Authorization

Required Operation Permission

Asset Tree Management

Full Access

Prerequisite

  • The asset to be updated must exist.

  • The fields to be updated must exist.

Request Format

POST https://{apigw-address}/asset-service/v2.1/assets?action=update

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

(deprecated) isPatchUpdate

Query

Optional

Boolean

This parameter is deprecated. It is recommended to use updateMode instead.

  • true (default): Only the fields specified in the parameters are updated. The values of those fields not specified will be retained.

  • false: The fields specified in the parameters are updated. Those fields not specified will have their existing values (if any) deleted.

updateMode

Query

Optional

String

The update method. If both updateMode and isPatchUpdate parameters are in the request, isPatchUpdate will be ignored. Available options are as per the below.

  • patchUpdate (default): Only the fields specified in the parameters are updated. The values of those fields not specified will be retained.

  • overwrite: All fields are updated. The values of those fields not specified will be changed to “null”.

  • tagDelete: Only the specified tags in tagKeys under the specified assetId are deleted. All fields not in tagKeys will remain unchanged.

Request Parameters (Body)

Name

Mandatory/Optional

Data Type

Description

asset

Mandatory

AssetUpdateVo Struct

The details for updating the asset. For more information, see AssetUpdateVo Struct.

Error Codes

Code

Message

Description

12404

Asset is not existent

The assetId cannot be found or does not exist.

12958

Asset validate failed

Update failed due to asset attribute verification failure.

Samples

Request Sample

url: https://{apigw-address}/asset-service/v2.1/assets?action=update&orgId=yourOrgId&updateMode=tagDelete
method: POST
requestBody:
{
  "asset": {
    "assetId": "yourAssetId",
    "name": {
      "defaultValue": "instanceName",
      "i18nValue": {
        "en_US": "English name ",
        "zh_CN": "Chinese name"
      }
    },
    "description": "description",
    "attributes": {
      "number": 135
    },
    "timezone": "+08:00",
    "tags": {
      "year": "2000",
      "author": "authorName"
    },
    "tagKeys": ["book1","book2"]
  }
}

Return Sample

{
  "code": 0,
  "msg": "OK",
  "requestId": "fa11232e-7e45-4176-a382-963c1240a27f"
}

Java SDK Sample

import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envisioniot.enos.asset_service.v2_1.UpdateAssetRequest;
import com.envisioniot.enos.asset_service.v2_1.UpdateAssetResponse;
import com.envisioniot.enos.asset_service.vo.AssetUpdateVo;

import java.util.HashMap;
import java.util.Map;

public class UpdateAsset {
    private static String accessKey = "yourAccessKey";
    private static String secretKey = "yourSecretKey";
    private static String orgId = "yourOrgId";
    private static String serverUrl = "https://{apigw-address}";

    //Make sure that an asset with this asset ID and the fields to be updated exist.

    public static void main(String[] args) {
        UpdateAssetRequest request = new UpdateAssetRequest();
        request.setOrgId(orgId);
        request.setUpdateMode(UpdateAssetRequest.UPDATE_MODE_TAG_DELETE);

        AssetUpdateVo asset = new AssetUpdateVo();
        Map<String,String> tags = new HashMap<>();
        tags.put("book1","book2");
        asset.setTags(tags);
        asset.setAssetId("yourAssetId");
        request.setAsset(asset);
        UpdateAssetResponse response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
                .url(serverUrl)
                .getResponse(request, request.getResponseClass());
        System.out.println(response);
    }
}