Help Center/ SecMaster/ API Reference/ API/ Workspace Management/ Querying the Workspace List
Updated on 2024-12-13 GMT+08:00

Querying the Workspace List

Function

This API is used to query workspace list. You can filter tenants' workspaces by workspace name, workspace description, and creation time.

Calling Method

For details, see Calling APIs.

URI

GET /v1/{project_id}/workspaces

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID.

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

offset

Yes

Number

Offset, which specifies the start position of the record to be returned. The value must be a number no less than 0.

limit

Yes

Number

Number of records displayed on each page

region_id

No

String

Region ID

name

No

String

This API is used to query the name.

description

No

String

Search by description

view_bind_id

No

String

Space ID bound to the view

view_bind_name

No

String

Space name bound to the view

create_time_start

No

String

Creation start time, for example, 2024-04-26T16:08:09Z+0800.

create_time_end

No

String

Creation end time, for example, 2024-04-2T16:08:09Z+0800.

is_view

No

Boolean

Indicates whether to query the view. The value can be true or false.

ids

No

String

Workspace ID array, which is separated by commas (,).

normal_project_id

No

String

General project ID.

enterprise_project_id

No

String

Enterprise project ID.

Request Parameters

Table 3 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

content-type

Yes

String

application/json;charset=UTF-8

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

workspaces

Array of CreateWorkspaceResponseBody objects

list of informations of workspaces

count

Number

Total data volume

Table 5 CreateWorkspaceResponseBody

Parameter

Type

Description

id

String

Workspace ID.

create_time

String

Creation time.

update_time

String

Update time.

name

String

Workspace name.

description

String

Workspace description.

creator_id

String

Creator ID.

creator_name

String

Creator name.

modifier_id

String

Modifier ID.

modifier_name

String

Modifier name.

project_id

String

Project ID.

project_name

String

Project name.

domain_id

String

Tenant ID.

domain_name

String

Tenant name.

enterprise_project_id

String

Enterprise project ID.

enterprise_project_name

String

Enterprise project name.

is_view

Boolean

Indicates whether the view is used.

region_id

String

Region ID.

view_bind_id

String

Space ID bound to the view.

view_bind_name

String

Space name bound to the view.

workspace_agency_list

Array of workspace_agency_list objects

This parameter is used only in the view scenario. The spaces managed by the view are listed.

Table 6 workspace_agency_list

Parameter

Type

Description

project_id

String

ID of the project to which the agency space belongs.

id

String

Space agency ID.

name

String

Space agency name.

region_id

String

ID of the region to which the agency space belongs

workspace_attribution

String

THIS_ACCOUNT: current account space; CROSS_ACCOUNT: cross-account space

agency_version

String

IAM agency version used when a user creates a hosting space. The value can be V3 or V5.

domain_id

String

ID of the tenant agency.

domain_name

String

Name of the tenant agency.

iam_agency_id

String

IAM agency ID.

iam_agency_name

String

IAM agency name.

resource_spec_code

Array of strings

The purchased version of agency space

selected

Boolean

Indicates whether a view is selected.

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

code

String

Error code.

message

String

Error description.

Status code: 500

Table 8 Response body parameters

Parameter

Type

Description

code

String

Error code.

message

String

Error description.

Example Requests

None

Example Responses

Status code: 200

Request successful.

{
  "count" : 1,
  "workspaces" : [ {
    "create_time" : "2024-07-02T09:25:17Z+0800",
    "creator_id" : "b4*****************************46a",
    "creator_name" : "l00644738",
    "description" : "My workspace",
    "domain_id" : "ac*****************************bf4",
    "domain_name" : "scc****09",
    "enterprise_project_id" : "",
    "enterprise_project_name" : "",
    "id" : "39*************bf",
    "is_view" : false,
    "modifier_id" : "",
    "modifier_name" : "",
    "name" : "My Workspace",
    "project_id" : "15**************************da6",
    "project_name" : "cn-north-4",
    "region_id" : "cn-north-4",
    "update_time" : "2024-07-02T09:25:17Z+0800",
    "view_bind_id" : "",
    "view_bind_name" : "",
    "workspace_agency_list" : [ ]
  } ]
}

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
46
47
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.secmaster.v2.region.SecMasterRegion;
import com.huaweicloud.sdk.secmaster.v2.*;
import com.huaweicloud.sdk.secmaster.v2.model.*;


public class ListWorkspacesSolution {

    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");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        SecMasterClient client = SecMasterClient.newBuilder()
                .withCredential(auth)
                .withRegion(SecMasterRegion.valueOf("<YOUR REGION>"))
                .build();
        ListWorkspacesRequest request = new ListWorkspacesRequest();
        try {
            ListWorkspacesResponse response = client.listWorkspaces(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
31
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdksecmaster.v2.region.secmaster_region import SecMasterRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdksecmaster.v2 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"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = SecMasterClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(SecMasterRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListWorkspacesRequest()
        response = client.list_workspaces(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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    secmaster "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v2/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")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := secmaster.NewSecMasterClient(
        secmaster.SecMasterClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListWorkspacesRequest{}
	response, err := client.ListWorkspaces(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 successful.

400

Invalid request parameter.

500

Request failed.

Error Codes

See Error Codes.