Updated on 2024-09-12 GMT+08:00

Creating a Flow

Function

This API is used to create a flow.

URI

POST /v2/{project_id}/fgs/workflows

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details, see Obtaining a Project ID.

Minimum: 1

Maximum: 64

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Flow name.

Minimum: 1

Maximum: 64

description

No

String

Flow description.

Minimum: 1

Maximum: 512

start

Yes

String

Start node ID.

Minimum: 1

Maximum: 256

triggers

No

Array of Trigger objects

Trigger list.

Array Length: 0 - 200

functions

Yes

Array of Function objects

Function list.

Array Length: 0 - 100

states

Yes

Array of OperationState objects

Node list. For details, see the descriptions of SleepState and OperationState.

Array Length: 1 - 100

constants

Yes

Object

Constants.

retries

Yes

Array of Retry objects

Retry policies.

Array Length: 0 - 200

mode

No

String

Flow type.- NORMAL: better for common services that take a long time to execute. Flows of this type support persistence and query of historical execution records and asynchronous invocation.- EXPRESS: better for services that take less than five minutes to execute but need premium performance. Flows of this type support both synchronous and asynchronous invocations, but do not support persistence of historical execution records.By default, NORMAL is used.

Default: NORMAL

Enumeration values:

  • NORMAL
  • EXPRESS

express_config

No

ExpressConfig object

Express flow configuration. This parameter is required when mode is set to EXPRESS.

enterprise_project_id

No

String

Enterprise project ID.

Minimum: 0

Maximum: 64

enable_stream_response

No

Boolean

Whether to return stream data.

Default: false

Table 3 Trigger

Parameter

Mandatory

Type

Description

trigger_name

Yes

String

Trigger name.

Minimum: 1

Maximum: 256

trigger_type

Yes

String

Trigger type. Options:

  • FLOWTIMER
  • SMN
  • APIG (shared)
  • APIG_DE (dedicated)
  • OBS (OBS triggers are not available in the International regions.)

Minimum: 1

Maximum: 32

Enumeration values:

  • FLOWTIMER
  • SMN
  • APIG
  • APIG_DE
  • OBS

enabled

No

Boolean

Whether to enable the trigger.

Default: true

Enumeration values:

  • true
  • false

trigger_config

No

OBSTriggerConfig object

OBS trigger configuration. This parameter is mandatory when trigger_type is set to OBS.

Table 4 OBSTriggerConfig

Parameter

Mandatory

Type

Description

bucket

Yes

String

OBS bucket name. This parameter is mandatory when trigger_type is set to OBS.

Minimum: 1

Maximum: 64

events

Yes

Array of strings

OBS events. This parameter is mandatory when trigger_type is set to OBS.

Array Length: 1 - 64

prefix

Yes

String

Object name prefix, which is mandatory when trigger_type is set to OBS.

Minimum: 1

Maximum: 1024

suffix

Yes

String

Object name suffix, which is mandatory when trigger_type is set to OBS.

Minimum: 1

Maximum: 1024

Table 5 Function

Parameter

Mandatory

Type

Description

name

Yes

String

Function name, which must be unique in a flow.

Minimum: 0

Maximum: 256

operation

Yes

String

Function URN.

Minimum: 0

Maximum: 256

metadata

No

Object

Custom function attribute.

Table 6 OperationState

Parameter

Mandatory

Type

Description

action_mode

No

String

Action execution mode. Serial and parallel modes are supported. The default mode is serial.

Minimum: 1

Maximum: 32

Enumeration values:

  • sequential
  • parallel

actions

Yes

Array of Action objects

Operations to be performed.

Array Length: 1 - 10

on_errors

No

Array of OnError objects

Error handling policy.

Array Length: 0 - 200

id

Yes

String

Node ID, which must be unique in the flow.

Minimum: 0

Maximum: 64

name

Yes

String

Node name.

Minimum: 1

Maximum: 256

type

Yes

String

Node type.

Minimum: 1

Maximum: 32

Enumeration values:

  • Operation
  • Sleep
  • End

end

Yes

Boolean

Whether the node is an end node.

transition

Yes

String

ID of the next node.

Minimum: 0

Maximum: 256

state_data_filter

No

StateDataFilter object

Filter expression.

duration

No

Long

Waiting time, in seconds. This parameter is mandatory and valid only when the node type is Sleep.

Minimum: 0.001

Maximum: 86400

Table 7 Action

Parameter

Mandatory

Type

Description

function_ref

No

FunctionRef object

Function invocation information.

Table 8 FunctionRef

Parameter

Mandatory

Type

Description

ref_name

Yes

String

Function reference name, which must be the same as the name in the outer functions.

Minimum: 0

Maximum: 256

invoke_mode

No

String

Function invocation mode. Currently, only synchronous invocation is supported.

Minimum: 1

Maximum: 32

Enumeration values:

  • synchronize
  • asynchronous

arguments

Yes

Object

Input parameters for function execution. Constants can be referenced.

Format: parameter path | constant value/path

The parameter path is the JSONPath (for example, $.a.b[0].c) of an input parameter.

The constant value can be a number, string (enclosed in single quotation marks), or Boolean.

The constant path is the JSONPath of a constant. It must be represented with $CONST for a root node. For example, $CONST.a.b.

Table 9 OnError

Parameter

Mandatory

Type

Description

error

No

String

Error matching expression, which is used to filter exceptions.

Minimum: 0

Maximum: 256

transition

No

String

ID of the next node.

Minimum: 0

Maximum: 256

retry_ref

No

String

Retry policy name.

Minimum: 0

Maximum: 256

Table 10 StateDataFilter

Parameter

Mandatory

Type

Description

input

No

String

Input filter expression (JSONPath).

Minimum: 0

Maximum: 256

output

No

String

Output filter expression (JSONPath).

Minimum: 0

Maximum: 256

Table 11 Retry

Parameter

Mandatory

Type

Description

name

Yes

String

Retry policy name, which must be unique in a flow.

Minimum: 1

Maximum: 256

delay

No

Long

Retry interval, in seconds. Default value: 1.

Minimum: 1

Maximum: 30

max_attempts

No

Long

Maximum number of retry attempts. Default value: 3.

Minimum: 1

Maximum: 8

Table 12 ExpressConfig

Parameter

Mandatory

Type

Description

log_level

No

String

Execution log level, which is valid only when mode is set to EXPRESS.

Options:

  • ALL: Execution logs of all nodes will be recorded.
  • ERROR: Only execution logs of abnormal nodes will be recorded. NONE: No logs will be recorded.

To set this parameter to ALL or ERROR, enable LTS first.

Minimum: 1

Maximum: 5

Enumeration values:

  • ALL
  • ERROR
  • NONE

Response Parameters

Status code: 201

Table 13 Response body parameters

Parameter

Type

Description

id

String

Unique flow ID.

Minimum: 1

Maximum: 64

workflow_urn

String

Flow URN. Format:urn:fss:<region_id>:<project_id>:workflow:<package>:<workflow_name>:<version>Currently, package and version can only be set to default and latest, respectively.

name

String

Flow name.

Minimum: 1

Maximum: 64

description

String

Flow description.

Minimum: 0

Maximum: 512

created_time

String

Flow creation time (UTC), in the format yyyy-MM-ddTHH:mm:ssZ.

Minimum: 0

Maximum: 64

updated_time

String

Flow modification time (UTC), in the format yyyy-MM-ddTHH:mm:ssZ.

Minimum: 0

Maximum: 64

created_by

String

Flow creator.

Minimum: 0

Maximum: 64

enable_stream_response

Boolean

Whether to return stream data.

Default: false

Status code: 400

Table 14 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

Minimum: 1

Maximum: 36

error_msg

String

Error description.

Minimum: 2

Maximum: 512

request_id

String

Request ID.

Minimum: 2

Maximum: 512

Status code: 500

Table 15 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

Minimum: 1

Maximum: 36

error_msg

String

Error description.

Minimum: 2

Maximum: 512

request_id

String

Request ID.

Minimum: 2

Maximum: 512

Example Requests

Create a function flow named workflow_test with start node test.

POST /v2/{project_id}/fgs/workflows

{
  "name" : "workflow_test",
  "start" : "test",
  "functions" : [ {
    "name" : "test",
    "operation" : "urn:fss:{regin}:c53626012ba84727b938ca8bf03108ef:test:latest"
  } ],
  "constants" : { },
  "states" : [ {
    "id" : "test",
    "name" : "test",
    "type" : "Operation",
    "end" : false,
    "transition" : "end",
    "actions" : [ {
      "function_ref" : {
        "ref_name" : "test",
        "arguments" : {
          "execution_name" : "$.test"
        }
      }
    } ]
  }, {
    "id" : "end",
    "name" : "end",
    "type" : "End",
    "end" : true,
    "transition" : "",
    "state_data_filter" : {
      "input" : "",
      "output" : ""
    },
    "actions" : [ ],
    "action_mode" : ""
  } ],
  "retries" : [ {
    "name" : "test"
  } ]
}

Example Responses

Status code: 201

Created

{
  "id" : "48aff955-ea10-4ffd-b426-190bc192dc14",
  "workflow_urn" : "urn:fss:cn-north-7:73d69ae0cfcf460190522d060f05ad:workflow:default:testflow:latest",
  "name" : "test-flow",
  "description" : "desc",
  "created_time" : "2021-01-01T00:00:00Z",
  "updated_time" : "2021-01-01T00:00:00Z",
  "created_by" : "admin"
}

Status Codes

Status Code

Description

201

Created

400

Bad Request

500

Internal Server Error

Error Codes

See Error Codes.