Updated on 2024-06-28 GMT+08:00

Querying a Script

Function

This API is used to query a script. You can specify a script name and creator for exact query. Information about the corresponding script will be returned.

Calling Method

For details, see Calling APIs.

URI

POST /v1/{project_id}/cms/script/list

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID.

Minimum: 32

Maximum: 32

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token obtained from IAM.

Minimum: 1

Maximum: 40960

Content-Type

Yes

String

Content type, which is application/json.

Minimum: 1

Maximum: 32

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

name

No

String

Parameter input for query. On the version management page, name refers to the script name, which cannot be empty. On the script management page, name refers to the parameter input for fuzzy query. If the value of name is null, all scripts will be queried by default.

Minimum: 0

Maximum: 128

is_default

No

String

Query rule. default: Script management page displayed and fuzzy query supported. no_default: Version management page displayed.

Minimum: 0

Maximum: 16

create_by

No

String

Creator. By default, scripts are searched by creator.

Minimum: 1

Maximum: 64

script_id

Yes

String

ID of the script to be queried during version management.

Minimum: 1

Maximum: 64

page_num

No

Integer

Page number, which is a positive integer.

Minimum: 1

Maximum: 100

page_size

No

Integer

Number of records displayed on each page. Default: 10.

Minimum: 1

Maximum: 1000

project_id

No

String

Project ID.

Minimum: 32

Maximum: 32

order_by_column

Yes

String

Field to be sorted. Options: name, create_time, and update_time (default).

Minimum: 1

Maximum: 16

sort_order

Yes

String

Sorting order (default: DESC). Options: ASC (ascending order) and DESC (descending order).

Minimum: 1

Maximum: 16

enterprise_project_id

No

String

Enterprise project ID, based on which you can search for required scripts.

Minimum: 1

Maximum: 64

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

elements

Array of Script objects

Query result set.

Array Length: 0 - 9999999

total_elements

Integer

Number of queried results.

Minimum: 0

Maximum: 99999999

Table 5 Script

Parameter

Type

Description

approve_info

ApproveInfo object

Review information.

create_by

String

Creator, for example, Tom.

Minimum: 1

Maximum: 64

create_time

Long

Creation time.

Minimum: 0

Maximum: 9999999999999

description

String

Script description, which can contain a maximum of 1000 characters.

Minimum: 0

Maximum: 1000

enterprise_project_id

String

Enterprise project ID.

Minimum: 1

Maximum: 64

id

String

Script ID, which is generated based on UUID.randomUUID.

Minimum: 1

Maximum: 64

name

String

Script name, which can contain digits, underscores (_), and letters.

Minimum: 1

Maximum: 64

online_exist_status

Boolean

Whether a version has been released. Options: true (a version has been released) and false (no version has been released).

online_id

String

ID of the released version.

Minimum: 1

Maximum: 64

project_id

String

Project ID obtained from IAM. Generally, a project ID contains 32 characters.

Minimum: 32

Maximum: 32

rate_control

RateControl object

Execution policy.

script_language

String

Script language. Options: SHELL, BAT, PYTHON, and POWER_SHELL.

Minimum: 1

Maximum: 16

update_by

String

User who makes the modification.

Minimum: 1

Maximum: 64

update_time

Long

Time when the entity was last updated. Note: When a creation, modification, or deletion operation is performed, update_time will be updated.

Minimum: 0

Maximum: 9999999999999

Table 6 ApproveInfo

Parameter

Type

Description

topic_selected

String

Selected topic.

Minimum: 1

Maximum: 2048

need_approve

Boolean

Whether a review is needed. Options: true and false (default).

smn_urn_list

String

Topic URN set.

Minimum: 1

Maximum: 2048

Table 7 RateControl

Parameter

Type

Description

have_rate_control

Boolean

Whether to implement batch release. Default: false.

time_delay

Integer

Interval.

Minimum: 1

Maximum: 60

max

Integer

Maximum number of instances supported for batch release.

Minimum: 0

Maximum: 100

Status code: 400

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Response code.

Minimum: 1

Maximum: 32

error_msg

String

Error message.

Minimum: 1

Maximum: 1024

http_code

Integer

Returned HTTP code.

Minimum: 1

Maximum: 999

Status code: 401

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Response code.

Minimum: 1

Maximum: 32

error_msg

String

Error message.

Minimum: 1

Maximum: 1024

http_code

Integer

Returned HTTP code.

Minimum: 1

Maximum: 999

Status code: 500

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Response code.

Minimum: 1

Maximum: 32

error_msg

String

Error message.

Minimum: 1

Maximum: 1024

http_code

Integer

Returned HTTP code.

Minimum: 1

Maximum: 999

Example Requests

Obtain the list of scripts whose name is xxx and sort order is DESC.

https://{endpoint}/v1/{project_id}/cms/script/list

{
  "name" : "xxx",
  "create_by" : "user1",
  "enterprise_project_id" : "",
  "page_num" : 1,
  "page_size" : 10,
  "is_default" : "default",
  "order_by_column" : "create_time",
  "sort_order" : "DESC",
  "script_id" : ""
}

Example Responses

Status code: 200

OK: The basic script information is returned.

{
  "elements" : [ {
    "approve_info" : {
      "need_approve" : false
    },
    "create_by" : "chenkaiyuan",
    "create_time" : 1600076223389,
    "description" : "fassfa",
    "enterprise_project_id" : "0",
    "id" : "xxxxxxxxxxxxxxxxxxx",
    "name" : "awffawsafws",
    "online_exist_status" : false,
    "project_id" : "xxxxxxxxxxxxxxxxxxx",
    "rate_control" : {
      "have_rate_control" : false,
      "max" : 0,
      "time_delay" : 0
    },
    "script_language" : "SHELL",
    "update_by" : "xxxx",
    "update_time" : 1600076223389
  } ],
  "total_elements" : 1
}

Status code: 400

Bad Request: Invalid request. The client should not repeat the request without modifications.

{
  "error_code" : "AOM.31002002",
  "error_message" : "Invalid script parameter.",
  "http_code" : 400
}

Status code: 401

Unauthorized: The authentication information is incorrect or invalid.

{
  "error_code" : "AOM.31009011",
  "error_msg" : "auth failed.",
  "http_code" : 401
}

Status code: 500

Internal Server Error: The server is able to receive the request but unable to understand the request.

{
  "error_code" : "AOM.31002005",
  "error_msg" : "script internal server error.",
  "http_code" : 500
}

SDK Sample Code

The SDK sample code is as follows.

Java

Obtain the list of scripts whose name is xxx and sort order is DESC.

 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
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.aom.v1.region.AomRegion;
import com.huaweicloud.sdk.aom.v1.*;
import com.huaweicloud.sdk.aom.v1.model.*;


public class ListAllScriptByNameSolution {

    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);

        AomClient client = AomClient.newBuilder()
                .withCredential(auth)
                .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                .build();
        ListAllScriptByNameRequest request = new ListAllScriptByNameRequest();
        SearchScriptsRequestBody body = new SearchScriptsRequestBody();
        body.withEnterpriseProjectId("");
        body.withSortOrder("DESC");
        body.withOrderByColumn("create_time");
        body.withPageSize(10);
        body.withPageNum(1);
        body.withScriptId("");
        body.withCreateBy("user1");
        body.withIsDefault("default");
        body.withName("xxx");
        request.withBody(body);
        try {
            ListAllScriptByNameResponse response = client.listAllScriptByName(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());
        }
    }
}

Python

Obtain the list of scripts whose name is xxx and sort order is DESC.

 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
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkaom.v1.region.aom_region import AomRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkaom.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 = BasicCredentials(ak, sk)

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

    try:
        request = ListAllScriptByNameRequest()
        request.body = SearchScriptsRequestBody(
            enterprise_project_id="",
            sort_order="DESC",
            order_by_column="create_time",
            page_size=10,
            page_num=1,
            script_id="",
            create_by="user1",
            is_default="default",
            name="xxx"
        )
        response = client.list_all_script_by_name(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Go

Obtain the list of scripts whose name is xxx and sort order is DESC.

 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
package main

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

    client := aom.NewAomClient(
        aom.AomClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListAllScriptByNameRequest{}
	enterpriseProjectIdSearchScriptsRequestBody:= ""
	pageSizeSearchScriptsRequestBody:= int32(10)
	pageNumSearchScriptsRequestBody:= int32(1)
	createBySearchScriptsRequestBody:= "user1"
	isDefaultSearchScriptsRequestBody:= "default"
	nameSearchScriptsRequestBody:= "xxx"
	request.Body = &model.SearchScriptsRequestBody{
		EnterpriseProjectId: &enterpriseProjectIdSearchScriptsRequestBody,
		SortOrder: "DESC",
		OrderByColumn: "create_time",
		PageSize: &pageSizeSearchScriptsRequestBody,
		PageNum: &pageNumSearchScriptsRequestBody,
		ScriptId: "",
		CreateBy: &createBySearchScriptsRequestBody,
		IsDefault: &isDefaultSearchScriptsRequestBody,
		Name: &nameSearchScriptsRequestBody,
	}
	response, err := client.ListAllScriptByName(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

More

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: The basic script information is returned.

400

Bad Request: Invalid request. The client should not repeat the request without modifications.

401

Unauthorized: The authentication information is incorrect or invalid.

500

Internal Server Error: The server is able to receive the request but unable to understand the request.

Error Codes

See Error Codes.