Querying an Account Organization
Function
This API is used to query an account organization.
Calling Method
For details, see Calling APIs.
Authorization Information
Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.
- If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
- If you are using identity policy-based authorization, no identity policy-based permissions are required for calling this API.
URI
GET /v5/setting/account/organization-tree
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| enterprise_project_id | No | String | Definition Enterprise project ID, which is used to filter assets in different enterprise projects. For details, see Obtaining an Enterprise Project ID. To query assets in all enterprise projects, set this parameter to all_granted_eps. Constraints You need to set this parameter only after the enterprise project function is enabled. Range The value can contain 1 to 256 characters. Default Value 0: default enterprise project. |
| is_refresh | No | Boolean | Definition Whether to ignore the local cache and forcibly synchronize the latest organization tree information from the organization service. Constraints No restrictions. You can choose whether to forcibly synchronize information as required. Range true (forcible synchronization), false (The local cache is used. This is the default value.) Default Value false |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| X-Security-Token | No | String | Definition Specifies the security token (session token) of your temporary security credentials. If a temporary security credential is used, this header is required. Constraints N/A Range The value contains 1 to 2,048 characters. Default Value N/A |
| X-Auth-Token | Yes | String | Definition User token, which contains user identity and permissions. The token can be used for identity authentication when an API is called. For details about how to obtain the token, see Obtaining a User Token. Constraints N/A Range The value can contain 1 to 32,768 characters. Default Value N/A |
| region | No | String | Definition Region ID, which is used to query assets in the required region. For details about how to obtain a region ID, see Obtaining a Region ID. Constraints N/A Range The value can contain 1 to 128 characters. Default Value N/A |
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| X-request-id | String | Request ID used for task tracing. The value format is request_uuid-timestamp-hostname. |
| Parameter | Type | Description |
|---|---|---|
| total_num | Integer | Definition Total number. Range The value range is 0 to 2,147,483,647. |
| data_list | Array of OrganizationNodeResponseInfo objects | Definition The list of details about the queried organization tree nodes. Range The length of the array ranges from 0 to the default value of limit of the current query. (Generally, the default value is 10. If it is specified, the default platform rule will be applied). The array elements are OrganizationNodeResponseInfo objects. |
| Parameter | Type | Description |
|---|---|---|
| parent_id | String | Definition Unique ID of the parent node of the current organization node, which is used to identify the hierarchy of the organization tree. (The parent ID of the root node is usually 0 or null). Range The value is a string of 1 to 64 characters and must comply with the naming rule of the platform organization node ID. |
| id | String | Definition Unique ID of an organization tree node, which uniquely identifies an organization node. Range The value is a string of 1 to 64 characters and complies with the naming rules of the platform organization node ID (for example, UUID or numbers). |
| urn | String | Definition URN of an organization node, which uniquely identifies an organization resource across services. Range A string that complies with the naming rules of the platform URN, containing 1 to 256 characters. The format is organizations::{management_account_id}:xxxxx:{org_id}/xxxxxxxx. |
| name | String | Definition Name of an organization node (which may be the name of an organization unit or account corresponding to org_type). Range The value can contain 1 to 64 characters, including letters, numbers, hyphens (-), and underscores (_). It cannot start or end with a special character. |
| org_type | String | Definition Type of the node (OU or account). Range unit (OU), account (account) |
| delegated | Boolean | Definition Whether the authorization of an organization node (OU or account) is complete. Range true (authorized, no need to be authorized again) or false (unauthorized, need to be authorized before being used) |
Example Requests
Query all account organizations in the root directory. Organization information is not forcibly synchronized from the organization.
GET https://{endpoint}/v5/setting/account/organization-tree?is_refresh=false&parent_id=root&enterprise_project_id=all_granted_eps Example Responses
Status code: 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 Sample Code
The SDK sample code is as follows.
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 36 37 38 39 40 41 42 43 44 45 46 47 | 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, err := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). SafeBuild() if err != nil { fmt.Println(err) return } hcClient, err := hss.HssClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). SafeBuild() if err != nil { fmt.Println(err) return } client := hss.NewHssClient(hcClient) request := &model.ListOrganizationTreeRequest{} response, err := client.ListOrganizationTree(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
| Status Code | Description |
|---|---|
| 200 | Request succeeded. |
Error Codes
See Error Codes.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot