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

Querying the Script Version

Function

This API is used to query all versions of a script based on the script ID. The versions of the specified script will be returned.

Calling Method

For details, see Calling APIs.

URI

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

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

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

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 ScriptVersion objects

Query result set.

Array Length: 0 - 9999999

total_elements

Integer

Number of queried results.

Minimum: 0

Maximum: 9999999

Table 5 ScriptVersion

Parameter

Type

Description

content

String

Script content, which cannot be empty.

Minimum: 1

Maximum: 30000

create_by

String

Creator, for example, Tom.

Minimum: 1

Maximum: 64

create_time

Long

Creation time.

Minimum: 0

Maximum: 9999999999999

enterprise_project_id

String

Enterprise project ID.

Minimum: 1

Maximum: 64

name

String

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

Minimum: 1

Maximum: 64

project_id

String

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

Minimum: 32

Maximum: 32

job_reference_number

Integer

Number of times that a script version is referenced by a job. Default: 0. Do not enter a negative number.

Minimum: 0

Maximum: 9999999

script_id

String

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

Minimum: 1

Maximum: 64

script_language

String

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

Minimum: 1

Maximum: 32

status_desc

Integer

Status. Options: 0 (unreleased), 1 (released); 2 (offline), and 3 (prohibited).

Minimum: 0

Maximum: 4

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

version_id

String

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

Minimum: 1

Maximum: 64

version_number

String

Script version number. Only digits, underscores (_), letters, and periods (.) are allowed.

Minimum: 1

Maximum: 64

job_reference_name

Array of ReferenceInfo objects

Details of a job referenced by a script.

Array Length: 0 - 9999999

Table 6 ReferenceInfo

Parameter

Type

Description

job_id

String

Job ID.

Minimum: 1

Maximum: 64

job_name

String

Job name.

Minimum: 1

Maximum: 64

Status code: 400

Table 7 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 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: 500

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

Example Requests

Query the script version based on a specified script ID.

POST https://{Endpoint}/v1/{project_id}/cms/script-version-list

{
  "script_id" : "xxxxxxxxxx",
  "page_num" : 1,
  "page_size" : 10,
  "order_by_column" : "update_time",
  "sort_order" : "ASC"
}

Example Responses

Status code: 200

OK: The version list of the specified script is returned.

{
  "elements" : [ {
    "content" : "1",
    "create_by" : "cxxxxx",
    "create_time" : 1676892212509,
    "enterprise_project_id" : "0",
    "job_reference_name" : [ {
      "job_id" : "012b43a3xxxxx684a30b52xxxx98cbe",
      "job_name" : "onxx_cxxxxxxxx"
    } ],
    "job_reference_number" : 1,
    "name" : "xxxxx",
    "project_id" : "2axxxxxcca548xxxxe891bxxxf",
    "script_id" : "xxxxaef-dbxx-41x9-8xx2-8exxxx4e159d2",
    "script_language" : "SHELL",
    "status_desc" : 1,
    "update_by" : "cxxxxx",
    "update_time" : 1672294768193,
    "version_id" : "xxxec4xx0-5x5-4bx0-a2xx-efeexx1c559f",
    "version_number" : "1"
  } ],
  "total_elements" : 1
}

Status code: 400

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

{
  "error_code" : "AOM.31002002",
  "error_msg" : "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

Query the script version based on a specified script ID.

 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 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 ListAllVersionByVersionIdSolution {

    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();
        ListAllVersionByVersionIdRequest request = new ListAllVersionByVersionIdRequest();
        SearchScriptsRequestBody body = new SearchScriptsRequestBody();
        body.withSortOrder("ASC");
        body.withOrderByColumn("update_time");
        body.withPageSize(10);
        body.withPageNum(1);
        body.withScriptId("xxxxxxxxxx");
        request.withBody(body);
        try {
            ListAllVersionByVersionIdResponse response = client.listAllVersionByVersionId(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

Query the script version based on a specified script ID.

 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
# 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 = ListAllVersionByVersionIdRequest()
        request.body = SearchScriptsRequestBody(
            sort_order="ASC",
            order_by_column="update_time",
            page_size=10,
            page_num=1,
            script_id="xxxxxxxxxx"
        )
        response = client.list_all_version_by_version_id(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

Query the script version based on a specified script ID.

 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
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.ListAllVersionByVersionIdRequest{}
	pageSizeSearchScriptsRequestBody:= int32(10)
	pageNumSearchScriptsRequestBody:= int32(1)
	request.Body = &model.SearchScriptsRequestBody{
		SortOrder: "ASC",
		OrderByColumn: "update_time",
		PageSize: &pageSizeSearchScriptsRequestBody,
		PageNum: &pageNumSearchScriptsRequestBody,
		ScriptId: "xxxxxxxxxx",
	}
	response, err := client.ListAllVersionByVersionId(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 version list of the specified script 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.