查询账号组织 - ListOrganizationTree
功能介绍
查询账号组织。
调用方法
请参见如何调用API。
授权信息
账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权,具体权限要求请参见权限和授权项。
- 如果使用身份策略授权,当前API调用无需身份策略权限。
URI
GET /v5/setting/account/organization-tree
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
enterprise_project_id |
否 |
String |
参数解释: 企业项目ID,用于过滤不同企业项目下的资产。获取方式请参见获取企业项目ID。 如需查询所有企业项目下的资产请传参“all_granted_eps”。 约束限制: 开通企业项目功能后才需要配置企业项目ID参数。 取值范围: 字符长度1-256位 默认取值: 0,表示默认企业项目(default)。 |
|
is_refresh |
否 |
Boolean |
参数解释: 控制是否忽略本地缓存,强制从组织服务同步最新的组织树信息; 约束限制: 无特殊约束,按需选择是否强制同步; 取值范围: true(强制同步)、false(使用本地缓存,默认) 默认取值: false |
请求参数
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
X-Security-Token |
否 |
String |
参数解释: 如果正在使用临时安全凭据,则此header是必需的,该值是临时安全凭据的安全令牌(会话令牌)。 约束限制: 不涉及 取值范围: 字符长度1-2048位 默认取值: 不涉及 |
|
X-Auth-Token |
是 |
String |
参数解释: 用户Token,包含了用户的身份、权限等信息,在调用API接口时,可通过Token进行身份认证。获取方式请参见获取用户Token。 约束限制: 不涉及 取值范围: 字符长度1-32768位 默认取值: 不涉及 |
|
region |
否 |
String |
参数解释: 区域ID,用于查询目的区域内的资产。获取方式请参见获取区域ID。 约束限制: 不涉及 取值范围: 字符长度1-128位 默认取值: 不涉及 |
响应参数
状态码:200
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
X-request-id |
String |
用于任务跟踪的请求ID号。格式为request_uuid-timestamp-hostname。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
total_num |
Integer |
参数解释: 总数 取值范围: 最小值0,最大值2147483647 |
|
data_list |
Array of OrganizationNodeResponseInfo objects |
参数解释 存储查询到的组织树节点详细信息列表; 取值范围 数组长度0-当前查询的默认limit值(常规默认10条,未指定时按平台默认规则),数组元素为OrganizationNodeResponseInfo对象 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
parent_id |
String |
参数解释 当前组织节点的父节点唯一标识ID,用于标识组织树层级关系(根节点父ID通常为“0”或空); 取值范围 字符长度1-64位,符合平台组织节点ID命名规范 |
|
id |
String |
参数解释 组织树节点的唯一标识ID,用于唯一确定某个组织节点; 取值范围 字符长度1-64位,符合平台组织节点ID命名规范(如UUID或数字组合) |
|
urn |
String |
参数解释 组织节点的统一资源名称(URN),用于跨服务唯一标识组织资源; 取值范围 字符长度1-256位,格式为organizations::{management_account_id}:xxxxx:{org_id}/xxxxxxxx,符合平台URN命名规范 |
|
name |
String |
参数解释 组织节点的名称(可能是组织单元名称或账号名称,与org_type对应); 取值范围 字符长度1-64位,支持字母、数字、连字符、下划线及中文,不能以特殊字符开头或结尾 |
|
org_type |
String |
参数解释: 节点(组织单元或账号)的类型; 取值范围: unit(组织单元)、account(账号) |
|
delegated |
Boolean |
参数解释: 标识组织节点(组织单元或账号)是否已完成授权; 取值范围: true(已授权,无需重复授权)、false(未授权,需完成授权后使用) |
请求示例
查询根目录下所有账号组织,不强制从organization同步组织信息
GET https://{endpoint}/v5/setting/account/organization-tree?is_refresh=false&parent_id=root&enterprise_project_id=all_granted_eps
响应示例
状态码:200
请求已成功
{
"data_list" : [ {
"parent_id" : "r-32rp34usb1n12d2sdk2cv2w7igod0lud",
"id" : "6a321faa6e6c4a18b5bf19dd954377b5",
"urn" : "organizations:6e5b687e10224a18af014e5d81bf9b3c:account:o-jbg8sokerqszi0zdo6vvaulwdsenonxz/6a321faa6e6c4a18b5bf19dd954377b5",
"name" : "scc_test",
"org_type" : "account",
"delegated" : true
} ],
"total_num" : 1
}
SDK代码示例
SDK代码示例如下。
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 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.hss.v5.region.HssRegion; import com.huaweicloud.sdk.hss.v5.*; import com.huaweicloud.sdk.hss.v5.model.*; public class ListOrganizationTreeSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); HssClient client = HssClient.newBuilder() .withCredential(auth) .withRegion(HssRegion.valueOf("<YOUR REGION>")) .build(); ListOrganizationTreeRequest request = new ListOrganizationTreeRequest(); try { ListOrganizationTreeResponse response = client.listOrganizationTree(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
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 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkhss.v5.region.hss_region import HssRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkhss.v5 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] credentials = BasicCredentials(ak, sk) client = HssClient.new_builder() \ .with_credentials(credentials) \ .with_region(HssRegion.value_of("<YOUR REGION>")) \ .build() try: request = ListOrganizationTreeRequest() response = client.list_organization_tree(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
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 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" hss "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := hss.NewHssClient( hss.HssClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ListOrganizationTreeRequest{} response, err := client.ListOrganizationTree(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
|
状态码 |
描述 |
|---|---|
|
200 |
请求已成功 |
错误码
请参见错误码。