Help Center/ SecMaster/ API Reference/ SecMaster APIs (V2)/ Security Analysis/ Creating Ad Hoc SQL Parameter Rendering
Updated on 2026-02-05 GMT+08:00

Creating Ad Hoc SQL Parameter Rendering

Function

This API is used create ad hoc SQL parameter rendering.

Calling Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/workspaces/{workspace_id}/siem/ad-hoc-queries/sql-render

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition

Project ID, which is used to specify the project that a resource belongs to. You can query the resources of a project by project ID. You can obtain the project ID from the API or console. Obtaining the Project ID

Constraints

N/A

Range

N/A

Default Value

N/A

workspace_id

Yes

String

Workspace ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition

User token. You can obtain it by calling the IAM API for obtaining a user token. The user token is the value of X-Subject-Token in the response header. Obtaining a User Token

Constraints

N/A

Range

N/A

Default Value

N/A

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

query

No

String

Query statement.

script_params

No

Array of ScriptParam objects

Script parameters.

transform_query

No

String

Query statement.

session_id

No

String

Console session ID.

time_zone

No

String

Time zone.

inter_active_params

No

Array of InterActiveParams objects

Interaction parameter list.

from

No

Long

Start.

to

No

Long

End.

Table 4 ScriptParam

Parameter

Mandatory

Type

Description

key

No

String

Key.

value

No

String

Value.

Table 5 InterActiveParams

Parameter

Mandatory

Type

Description

key

No

String

Key.

value

No

String

Value.

operator

No

String

Query operation.

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

operate_id

String

Flink SQL gateway operation ID, which is used to query data.

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error description.

Example Requests

{
  "from" : 0,
  "inter_active_params" : [ {
    "key" : "d0f10807-51b7-4d4c-847d-876d4fd7dc50",
    "operator" : "494426cf-a02d-4f6f-93d4-f4c30164517f",
    "value" : "04753b6e-c20b-4586-ad65-a9113eacdbf3"
  }, {
    "key" : "dc58e65a-e410-41f0-a84d-ca03437aa34b",
    "operator" : "9d9d03fa-595f-4388-90ca-99941faa9972",
    "value" : "e8c10bdf-48b6-4541-85ae-5a333700135c"
  } ],
  "query" : "384247bb-2114-4bca-a781-eb71abf65d35",
  "script_params" : [ {
    "key" : "5dbecad6-4c1a-48b7-a0df-1d211c793c55",
    "value" : "36a16ba4-6c12-4e13-8be0-8793ab93c055"
  }, {
    "key" : "24a31a0f-0182-4f60-a04b-72a59da614b3",
    "value" : "52b87a0b-64c3-4434-b894-b5132d0e6afc"
  } ],
  "session_id" : "3ddb28e7-5ffe-4089-8509-77f308bd1b5c",
  "time_zone" : "ce4ea29b-3767-4e75-8945-2b83c1cc156a",
  "to" : 0,
  "transform_query" : "bfd4a5dc-6ab5-4e38-9714-ee018c141f06"
}

Example Responses

Status code: 200

Successful.

{
  "operate_id" : "ae4f9fb0-efcb-41cf-9be3-e99c825d6e60"
}

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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.*;

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

public class CreateSqlRenderSolution {

    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();
        CreateSqlRenderRequest request = new CreateSqlRenderRequest();
        request.withWorkspaceId("{workspace_id}");
        CreateSqlRenderRequestBody body = new CreateSqlRenderRequestBody();
        List<InterActiveParams> listbodyInterActiveParams = new ArrayList<>();
        listbodyInterActiveParams.add(
            new InterActiveParams()
                .withKey("d0f10807-51b7-4d4c-847d-876d4fd7dc50")
                .withValue("04753b6e-c20b-4586-ad65-a9113eacdbf3")
                .withOperator("494426cf-a02d-4f6f-93d4-f4c30164517f")
        );
        listbodyInterActiveParams.add(
            new InterActiveParams()
                .withKey("dc58e65a-e410-41f0-a84d-ca03437aa34b")
                .withValue("e8c10bdf-48b6-4541-85ae-5a333700135c")
                .withOperator("9d9d03fa-595f-4388-90ca-99941faa9972")
        );
        List<ScriptParam> listbodyScriptParams = new ArrayList<>();
        listbodyScriptParams.add(
            new ScriptParam()
                .withKey("5dbecad6-4c1a-48b7-a0df-1d211c793c55")
                .withValue("36a16ba4-6c12-4e13-8be0-8793ab93c055")
        );
        listbodyScriptParams.add(
            new ScriptParam()
                .withKey("24a31a0f-0182-4f60-a04b-72a59da614b3")
                .withValue("52b87a0b-64c3-4434-b894-b5132d0e6afc")
        );
        body.withTo(0L);
        body.withFrom(0L);
        body.withInterActiveParams(listbodyInterActiveParams);
        body.withTimeZone("ce4ea29b-3767-4e75-8945-2b83c1cc156a");
        body.withSessionId("3ddb28e7-5ffe-4089-8509-77f308bd1b5c");
        body.withTransformQuery("bfd4a5dc-6ab5-4e38-9714-ee018c141f06");
        body.withScriptParams(listbodyScriptParams);
        body.withQuery("384247bb-2114-4bca-a781-eb71abf65d35");
        request.withBody(body);
        try {
            CreateSqlRenderResponse response = client.createSqlRender(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
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
# 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 = CreateSqlRenderRequest()
        request.workspace_id = "{workspace_id}"
        listInterActiveParamsbody = [
            InterActiveParams(
                key="d0f10807-51b7-4d4c-847d-876d4fd7dc50",
                value="04753b6e-c20b-4586-ad65-a9113eacdbf3",
                operator="494426cf-a02d-4f6f-93d4-f4c30164517f"
            ),
            InterActiveParams(
                key="dc58e65a-e410-41f0-a84d-ca03437aa34b",
                value="e8c10bdf-48b6-4541-85ae-5a333700135c",
                operator="9d9d03fa-595f-4388-90ca-99941faa9972"
            )
        ]
        listScriptParamsbody = [
            ScriptParam(
                key="5dbecad6-4c1a-48b7-a0df-1d211c793c55",
                value="36a16ba4-6c12-4e13-8be0-8793ab93c055"
            ),
            ScriptParam(
                key="24a31a0f-0182-4f60-a04b-72a59da614b3",
                value="52b87a0b-64c3-4434-b894-b5132d0e6afc"
            )
        ]
        request.body = CreateSqlRenderRequestBody(
            to=0,
            _from=0,
            inter_active_params=listInterActiveParamsbody,
            time_zone="ce4ea29b-3767-4e75-8945-2b83c1cc156a",
            session_id="3ddb28e7-5ffe-4089-8509-77f308bd1b5c",
            transform_query="bfd4a5dc-6ab5-4e38-9714-ee018c141f06",
            script_params=listScriptParamsbody,
            query="384247bb-2114-4bca-a781-eb71abf65d35"
        )
        response = client.create_sql_render(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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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.CreateSqlRenderRequest{}
	request.WorkspaceId = "{workspace_id}"
	keyInterActiveParams:= "d0f10807-51b7-4d4c-847d-876d4fd7dc50"
	valueInterActiveParams:= "04753b6e-c20b-4586-ad65-a9113eacdbf3"
	operatorInterActiveParams:= "494426cf-a02d-4f6f-93d4-f4c30164517f"
	keyInterActiveParams1:= "dc58e65a-e410-41f0-a84d-ca03437aa34b"
	valueInterActiveParams1:= "e8c10bdf-48b6-4541-85ae-5a333700135c"
	operatorInterActiveParams1:= "9d9d03fa-595f-4388-90ca-99941faa9972"
	var listInterActiveParamsbody = []model.InterActiveParams{
        {
            Key: &keyInterActiveParams,
            Value: &valueInterActiveParams,
            Operator: &operatorInterActiveParams,
        },
        {
            Key: &keyInterActiveParams1,
            Value: &valueInterActiveParams1,
            Operator: &operatorInterActiveParams1,
        },
    }
	keyScriptParams:= "5dbecad6-4c1a-48b7-a0df-1d211c793c55"
	valueScriptParams:= "36a16ba4-6c12-4e13-8be0-8793ab93c055"
	keyScriptParams1:= "24a31a0f-0182-4f60-a04b-72a59da614b3"
	valueScriptParams1:= "52b87a0b-64c3-4434-b894-b5132d0e6afc"
	var listScriptParamsbody = []model.ScriptParam{
        {
            Key: &keyScriptParams,
            Value: &valueScriptParams,
        },
        {
            Key: &keyScriptParams1,
            Value: &valueScriptParams1,
        },
    }
	toCreateSqlRenderRequestBody:= int64(0)
	fromCreateSqlRenderRequestBody:= int64(0)
	timeZoneCreateSqlRenderRequestBody:= "ce4ea29b-3767-4e75-8945-2b83c1cc156a"
	sessionIdCreateSqlRenderRequestBody:= "3ddb28e7-5ffe-4089-8509-77f308bd1b5c"
	transformQueryCreateSqlRenderRequestBody:= "bfd4a5dc-6ab5-4e38-9714-ee018c141f06"
	queryCreateSqlRenderRequestBody:= "384247bb-2114-4bca-a781-eb71abf65d35"
	request.Body = &model.CreateSqlRenderRequestBody{
		To: &toCreateSqlRenderRequestBody,
		From: &fromCreateSqlRenderRequestBody,
		InterActiveParams: &listInterActiveParamsbody,
		TimeZone: &timeZoneCreateSqlRenderRequestBody,
		SessionId: &sessionIdCreateSqlRenderRequestBody,
		TransformQuery: &transformQueryCreateSqlRenderRequestBody,
		ScriptParams: &listScriptParamsbody,
		Query: &queryCreateSqlRenderRequestBody,
	}
	response, err := client.CreateSqlRender(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

Successful.

400

Error response.

Error Codes

See Error Codes.