Updated on 2026-02-05 GMT+08:00

Creating a Workflow Instance

Function

This API is used to create a workflow instance.

Calling Method

For details, see Calling APIs.

URI

POST /v1/{project_id}/workspaces/{workspace_id}/soc/workflows/{workflow_id}/instances

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

Definition

Workspace ID.

Range

N/A

workflow_id

Yes

String

Workflow 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

Content-Type

Yes

String

Definition

Content type.

  • application/json;charset=UTF-8: common API request type

Constraints

N/A

Range

  • application/json;charset=UTF-8

Default Value

N/A

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

command_type

Yes

String

Definition

Commands used to operate a workflow instance.

  • ActionInstanceRunCommand: runs a workflow instance.

Constraints

N/A

Range

  • ActionInstanceRunCommand

Default Value

N/A

action_type

Yes

String

Definition

Action type.

  • workflow: workflow

Constraints

N/A

Range

  • workflow

Default Value

N/A

action_id

No

String

Definition

Workflow ID.

Constraints

N/A

action_instance_id

No

String

Definition

Workflow instance ID.

Constraints

N/A

playbook_context

No

PlaybookcontextRef object

Execution context.

Table 4 PlaybookcontextRef

Parameter

Mandatory

Type

Description

data_object

Yes

DataObjectRefInfo object

Workflow execution context.

Table 5 DataObjectRefInfo

Parameter

Mandatory

Type

Description

content

No

Map<String,Object>

Workflow instance context.

dataclass

No

DataClassRef object

Data class information.

Table 6 DataClassRef

Parameter

Mandatory

Type

Description

id

No

String

Definition

Data class ID.

Range

N/A

name

Yes

String

Definition

Data class name.

Range

N/A

Response Parameters

Status code: 200

Table 7 Response body parameters

Parameter

Type

Description

command_type

String

Definition

Commands used to operate a workflow instance.

  • ActionInstanceRunCommand: runs a workflow instance.

Constraints

N/A

Range

  • ActionInstanceRunCommand

Default Value

N/A

action_type

String

Definition

Action type.

  • workflow: workflow

Constraints

N/A

Range

  • workflow

Default Value

N/A

action_id

String

Definition

Workflow ID.

Constraints

N/A

action_instance_id

String

Definition

Workflow instance ID.

Constraints

N/A

playbook_context

PlaybookcontextRef object

Execution context.

Table 8 PlaybookcontextRef

Parameter

Type

Description

data_object

DataObjectRefInfo object

Workflow execution context.

Table 9 DataObjectRefInfo

Parameter

Type

Description

content

Map<String,Object>

Workflow instance context.

dataclass

DataClassRef object

Data class information.

Table 10 DataClassRef

Parameter

Type

Description

id

String

Definition

Data class ID.

Range

N/A

name

String

Definition

Data class name.

Range

N/A

Example Requests

The workflow instance for running alert data classes

{
  "command_type" : "ActionInstanceRunCommand",
  "action_type" : "workflow",
  "action_id" : "446255ce-XXXXXXXXXX-0b4931",
  "action_instance_id" : "1111xxxxxxxxxxxxxx111",
  "playbook_context" : {
    "data_object" : {
      "dataclass" : {
        "name" : "Alert"
      },
      "content" : {
        "name" : { },
        "key" : { }
      }
    }
  }
}

Example Responses

Status code: 200

Response to the operation of a workflow instance.

{
  "command_type" : "ActionInstanceRunCommand",
  "action_type" : "workflow",
  "action_id" : "446255ce-XXXXXXXXXX-0b4931",
  "action_instance_id" : "1111xxxxxxxxxxxxxx111",
  "playbook_context" : {
    "data_object" : {
      "dataclass" : {
        "name" : "Alert"
      },
      "content" : {
        "name" : { },
        "key" : { }
      }
    }
  }
}

SDK Sample Code

The SDK sample code is as follows.

The workflow instance for running alert data classes

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

import java.util.Map;
import java.util.HashMap;

public class CreateWorkflowInstanceSolution {

    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();
        CreateWorkflowInstanceRequest request = new CreateWorkflowInstanceRequest();
        request.withWorkspaceId("{workspace_id}");
        request.withWorkflowId("{workflow_id}");
        AopInstanceEventData body = new AopInstanceEventData();
        DataClassRef dataclassDataObject = new DataClassRef();
        dataclassDataObject.withName("Alert");
        Map<String, Object> listDataObjectContent = new HashMap<>();
        listDataObjectContent.put("name", new Object());
        listDataObjectContent.put("key", new Object());
        DataObjectRefInfo dataObjectPlaybookContext = new DataObjectRefInfo();
        dataObjectPlaybookContext.withContent(listDataObjectContent)
            .withDataclass(dataclassDataObject);
        PlaybookcontextRef playbookContextbody = new PlaybookcontextRef();
        playbookContextbody.withDataObject(dataObjectPlaybookContext);
        body.withPlaybookContext(playbookContextbody);
        body.withActionInstanceId("1111xxxxxxxxxxxxxx111");
        body.withActionId("446255ce-XXXXXXXXXX-0b4931");
        body.withActionType(AopInstanceEventData.ActionTypeEnum.fromValue("workflow"));
        body.withCommandType(AopInstanceEventData.CommandTypeEnum.fromValue("ActionInstanceRunCommand"));
        request.withBody(body);
        try {
            CreateWorkflowInstanceResponse response = client.createWorkflowInstance(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());
        }
    }
}

The workflow instance for running alert data classes

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

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdksecmaster.v1.region.secmaster_region import SecMasterRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdksecmaster.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"]
    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 = CreateWorkflowInstanceRequest()
        request.workspace_id = "{workspace_id}"
        request.workflow_id = "{workflow_id}"
        dataclassDataObject = DataClassRef(
            name="Alert"
        )
        listContentDataObject = {
            "name": {},
            "key": {}
        }
        dataObjectPlaybookContext = DataObjectRefInfo(
            content=listContentDataObject,
            dataclass=dataclassDataObject
        )
        playbookContextbody = PlaybookcontextRef(
            data_object=dataObjectPlaybookContext
        )
        request.body = AopInstanceEventData(
            playbook_context=playbookContextbody,
            action_instance_id="1111xxxxxxxxxxxxxx111",
            action_id="446255ce-XXXXXXXXXX-0b4931",
            action_type="workflow",
            command_type="ActionInstanceRunCommand"
        )
        response = client.create_workflow_instance(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

The workflow instance for running alert data classes

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

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    secmaster "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/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")
    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.CreateWorkflowInstanceRequest{}
	request.WorkspaceId = "{workspace_id}"
	request.WorkflowId = "{workflow_id}"
	dataclassDataObject := &model.DataClassRef{
		Name: "Alert",
	}
	var listContentDataObject = map[string]interface{}{
        "name": make(map[string]string),
        "key": make(map[string]string),
    }
	dataObjectPlaybookContext := &model.DataObjectRefInfo{
		Content: listContentDataObject,
		Dataclass: dataclassDataObject,
	}
	playbookContextbody := &model.PlaybookcontextRef{
		DataObject: dataObjectPlaybookContext,
	}
	actionInstanceIdAopInstanceEventData:= "1111xxxxxxxxxxxxxx111"
	actionIdAopInstanceEventData:= "446255ce-XXXXXXXXXX-0b4931"
	request.Body = &model.AopInstanceEventData{
		PlaybookContext: playbookContextbody,
		ActionInstanceId: &actionInstanceIdAopInstanceEventData,
		ActionId: &actionIdAopInstanceEventData,
		ActionType: model.GetAopInstanceEventDataActionTypeEnum().WORKFLOW,
		CommandType: model.GetAopInstanceEventDataCommandTypeEnum().ACTION_INSTANCE_RUN_COMMAND,
	}
	response, err := client.CreateWorkflowInstance(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

Response to the operation of a workflow instance.

Error Codes

See Error Codes.