Get Assets by Application

查询当前用户在某个应用下有权限的所有资产。

约束条件

  • 关联的应用已被组织购买
  • 应用需被组织管理员授予访问用户资产的权限

请求格式

GET https://{apigw-address}/app-portal-service/v2.2/user/app/asset/tree

请求参数(URI)

名称 位置(Path/Query) 必需/可选 数据类型 描述
accessKey Query 必需 String 应用的服务账号,应用以 accessKey 进行鉴权以获得其被授权访问的数据。如何获取accessKey信息>>

响应参数

名称 数据类型 描述
data data结构体 资产列表。

data结构体

名称 数据类型 描述
id String 节点ID。
name String 节点名称。
tag String 节点标签,如果当前节点为资产,则标签为”asset”,否则此节点为组织结构节点,对应标签为“null”。(由于资产只能挂载到组织结构的叶子节点上,所以当此标签为”asset”时,必有父节点且父节点为组织结构节点,同时必然没有子节点)。
parentId String 父节点ID。
children data结构体列表 子节点。

错误码

代码 描述
31400 AccessKey不能为空
31401 提供的Access Token无效
31403 没有此应用权限
31404 应用不存在或组织未购买此应用

示例

请求示例

url: https://{apigw-address}/app-portal-service/v2.2/user/app/asset/tree?accessKey=app_1

method: GET

headers: {"Authorization":"Bearer APP_PORTAL_S_TDKKeqfYBK3m5z3LRgKVqThWDYnRBN44"}

返回示例

{
  "code": 0,
  "message": "OK",
  "data": {
    "id": "sg1566xxxxxxxxxx",
    "name": "Solar_shangHai",
    "tag": null,
    "parentId": "",
    "children": [
      {
        "id": "sg15663524029331",
        "name": "江阴",
        "tag": null,
        "parentId": "sg1566xxxxxxxxxx",
        "children": [
          {
            "id": "zULM004t",
            "name": "Solar_Assert",
            "tag": "asset",
            "parentId": "",
            "children": null
          },
          {
            "id": "osvxGtJC",
            "name": "shangHai",
            "tag": "asset",
            "parentId": "",
            "children": null
          }
        ]
      }
    ]
  }
}

Java SDK 调用示例

public class AppPortalSdkTest{
    @Test
    public void getAssetsByApplicationTest() {
        AssetRequest assetRequest = new AssetRequest("your_access_key", "your_access_token");
        AssetResponse assetResponse = Poseidon.config(PConfig.init().appKey("your_access_key").appSecret("your_secret_key").debug())
                .url("https://{apigw-address}").getResponse(assetRequest, AssetResponse.class);

        System.out.println("Get app asset tree res: " + JSON.toJSONString(assetResponse));

        assertNotNull("Response should not be null", assetResponse);
        assertNotNull("Response data should not be null", assetResponse.data);

        assertNotNull("Asset id should not be null", assetResponse.data.id);
    }
}