Updated on 2024-11-11 GMT+08:00

Listing Resources in an Enterprise Project

Function

This API is used to query resources added to an enterprise project.

Calling Method

For details, see Calling APIs.

URI

POST /v1.0/enterprise-projects/{enterprise_project_id}/resources/filter

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

enterprise_project_id

Yes

String

Enterprise project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Specifies the user token. EPS is a global service. Therefore, when calling the IAM API to obtain a user token, set the scope field to domain. The value of X-Subject-Token in the response header is the user token.

X-Security-Token

No

String

Security token (session token) of your temporary security credentials. If a temporary security credential is used, this header is required.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

projects

No

Array of strings

Project IDs. This parameter is mandatory when resource_types contains a region-level service.

resource_types

Yes

Array of strings

Specifies the resource type list. The value of this parameter is case sensitive. For example, ecs,scaling_group, images, disk, vpcs,security-groups, shared_bandwidth,eip and cdn. For details, see the section "Appendix - Resource Types Supported by EPS".

offset

No

Integer

Index position. The query starts from the next data record specified by offset. The value must be a number and cannot be a negative number. The default value is 0.

limit

No

Integer

Number of records to be queried. If this parameter is not passed, the default value 1000 is used. The maximum value is 1000 and the minimum value is 1.

matches

No

Array of Match objects

Search field. key indicates the field to be matched and is fixed at resource_name. value indicates the value to be matched. If this field is not passed, no matching condition will be used.

Table 4 Match

Parameter

Mandatory

Type

Description

key

Yes

String

Key. If the matches parameter is passed, this parameter is mandatory and is fixed at resource_name.

value

Yes

String

Value, which is the resource name. If the matches parameter is passed, this parameter is mandatory and fuzzy search is used by default, for example, message.com. A value can contain a maximum of 255 characters.

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

resources

Array of Resources objects

Resource list.

errors

Array of Errors objects

Resources bound to enterprise projects that failed to be queried.

total_count

Integer

Total number of resources in enterprise projects.

Table 6 Resources

Parameter

Type

Description

enterprise_project_id

String

Enterprise project ID.

project_id

String

ProjectID

project_name

String

Project name.

resource_detail

Object

Resource details.

resource_id

String

Resource ID.

resource_name

String

Resource name.

resource_type

String

Resource type.

Table 7 Errors

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

project_id

String

ProjectID

resource_type

String

Resource type.

Status code: 400

Table 8 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 9 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 401

Table 10 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 11 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 402

Table 12 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 13 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 403

Table 14 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 15 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 404

Table 16 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 17 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 405

Table 18 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 19 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 406

Table 20 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 21 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 407

Table 22 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 23 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 408

Table 24 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 25 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 409

Table 26 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 27 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 500

Table 28 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 29 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 501

Table 30 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 31 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 502

Table 32 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 33 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 503

Table 34 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 35 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 504

Table 36 Response body parameters

Parameter

Type

Description

error

RespErrorMessage object

Error request information.

Table 37 RespErrorMessage

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Requests

Listing Resources in an Enterprise Project

POST https://{Endpoint}/v1.0/enterprise-projects/{enterprise_project_id}/resources/filter

{
  "projects" : [ "e1eb7c40cbea4c8389cde527594a306d", "2345d321da864d6faf2e762647e19f96" ],
  "resource_types" : [ "disk" ],
  "offset" : 0,
  "limit" : 10,
  "matches" : [ {
    "key" : "resource_name",
    "value" : "lhj"
  } ]
}

Example Responses

Status code: 200

OK

{
  "resources" : [ {
    "project_id" : "e1eb7c40cbea4c8389cde527594a306d",
    "project_name" : "XXXX",
    "resource_type" : "disk",
    "resource_id" : "b621f5ae-b5c1-49d7-a660-752c445434b4",
    "resource_name" : "lhj1-volume-0001",
    "resource_detail" : null,
    "enterprise_project_id" : "0"
  }, {
    "project_id" : "e1eb7c40cbea4c8389cde527594a306d",
    "project_name" : "XXXX",
    "resource_type" : "disk",
    "resource_id" : "87c9edc9-f66c-48b8-a22f-372b2e22d579",
    "resource_name" : "lhj2-volume-0002",
    "resource_detail" : null,
    "enterprise_project_id" : "0"
  } ],
  "errors" : [ ],
  "total_count" : 2
}

SDK Sample Code

The SDK sample code is as follows.

Listing Resources in an Enterprise Project

 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.GlobalCredentials;
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.eps.v1.region.EpsRegion;
import com.huaweicloud.sdk.eps.v1.*;
import com.huaweicloud.sdk.eps.v1.model.*;

import java.util.List;
import java.util.ArrayList;

public class ShowResourceBindEnterpriseProjectSolution {

    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 GlobalCredentials()
                .withAk(ak)
                .withSk(sk);

        EpsClient client = EpsClient.newBuilder()
                .withCredential(auth)
                .withRegion(EpsRegion.valueOf("<YOUR REGION>"))
                .build();
        ShowResourceBindEnterpriseProjectRequest request = new ShowResourceBindEnterpriseProjectRequest();
        request.withEnterpriseProjectId("{enterprise_project_id}");
        ResqEpResouce body = new ResqEpResouce();
        List<Match> listbodyMatches = new ArrayList<>();
        listbodyMatches.add(
            new Match()
                .withKey("resource_name")
                .withValue("lhj")
        );
        List<String> listbodyResourceTypes = new ArrayList<>();
        listbodyResourceTypes.add("disk");
        List<String> listbodyProjects = new ArrayList<>();
        listbodyProjects.add("e1eb7c40cbea4c8389cde527594a306d");
        listbodyProjects.add("2345d321da864d6faf2e762647e19f96");
        body.withMatches(listbodyMatches);
        body.withLimit(10);
        body.withOffset(0);
        body.withResourceTypes(listbodyResourceTypes);
        body.withProjects(listbodyProjects);
        request.withBody(body);
        try {
            ShowResourceBindEnterpriseProjectResponse response = client.showResourceBindEnterpriseProject(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());
        }
    }
}

Listing Resources in an Enterprise Project

 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
48
49
50
51
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdkeps.v1.region.eps_region import EpsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkeps.v1 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 = GlobalCredentials(ak, sk)

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

    try:
        request = ShowResourceBindEnterpriseProjectRequest()
        request.enterprise_project_id = "{enterprise_project_id}"
        listMatchesbody = [
            Match(
                key="resource_name",
                value="lhj"
            )
        ]
        listResourceTypesbody = [
            "disk"
        ]
        listProjectsbody = [
            "e1eb7c40cbea4c8389cde527594a306d",
            "2345d321da864d6faf2e762647e19f96"
        ]
        request.body = ResqEpResouce(
            matches=listMatchesbody,
            limit=10,
            offset=0,
            resource_types=listResourceTypesbody,
            projects=listProjectsbody
        )
        response = client.show_resource_bind_enterprise_project(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Listing Resources in an Enterprise Project

 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
48
49
50
51
52
53
54
55
56
57
58
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
    eps "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/eps/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/eps/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/eps/v1/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 := global.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := eps.NewEpsClient(
        eps.EpsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ShowResourceBindEnterpriseProjectRequest{}
	request.EnterpriseProjectId = "{enterprise_project_id}"
	var listMatchesbody = []model.Match{
        {
            Key: "resource_name",
            Value: "lhj",
        },
    }
	var listResourceTypesbody = []string{
        "disk",
    }
	var listProjectsbody = []string{
        "e1eb7c40cbea4c8389cde527594a306d",
	    "2345d321da864d6faf2e762647e19f96",
    }
	limitResqEpResouce:= int32(10)
	offsetResqEpResouce:= int32(0)
	request.Body = &model.ResqEpResouce{
		Matches: &listMatchesbody,
		Limit: &limitResqEpResouce,
		Offset: &offsetResqEpResouce,
		ResourceTypes: listResourceTypesbody,
		Projects: &listProjectsbody,
	}
	response, err := client.ShowResourceBindEnterpriseProject(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

OK

400

Bad Request

401

Unauthorized

402

Payment Required

403

Forbidden

404

Not Found

405

Method Not Allowed

406

Not Acceptable

407

Proxy Authentication Required

408

Request Timeout

409

Conflict

500

Internal Server Error

501

Not Implemented

502

Bad Gateway

503

Service Unavailable

504

Gateway Timeout

Error Codes

See Error Codes.