Updated on 2024-07-11 GMT+08:00

Conditional Branch Operator

The Conditional Branch operator obtains the request parameters or result sets of its upstream operator for condition judgment and determines the next branch to be executed based on the defined expression. If the conditions of multiple branches are met, only the first branch is executed.

Table 1 Conditional Branch operator parameters

Parameter

Description

Branch 1

Condition Type

Condition type.
  • Meets the current condition: When data transferred to the conditional branch meets the specified expression, the branch is executed.
  • Does not meet other conditions: When data transferred to the conditional branch does not meet the conditions of any other branch, the branch is executed.

Expression

This parameter is mandatory when Condition Type is Meets the current condition.

The expression consists of the code and variable name of the upstream operator. For details about how to use the expression, see Defining an Expression.

Branch 2

Condition Type

Condition type.
  • Meets the current condition: When data transferred to the conditional branch meets the specified expression, the branch is executed.
  • Does not meet other conditions: When data transferred to the conditional branch does not meet the conditions of any other branch, the branch is executed.

Expression

This parameter is mandatory when Condition Type is Meets the current condition.

The expression consists of the code and variable name of the upstream operator. For details about how to use the expression, see Defining an Expression.

...

Branch n

Condition Type

Condition type.
  • Meets the current condition: When data transferred to the conditional branch meets the specified expression, the branch is executed.
  • Does not meet other conditions: When data transferred to the conditional branch does not meet the conditions of any other branch, the branch is executed.
  • Meets the current condition: When data transferred to the conditional branch meets the specified expression, the branch is executed.
  • Does not meet other conditions: When data transferred to the conditional branch does not meet the conditions of any other branch, the branch is executed.

Expression

This parameter is mandatory when Condition Type is Meets the current condition.

The expression consists of the code and variable name of the upstream operator. For details about how to use the expression, see Defining an Expression.

Defining an Expression

When defining the expression of a conditional branch, you need to configure a variable expression. Variable expressions are available for Entry API and Common API operators, but unavailable for Conditional Branch, Parallel Processing, and Output Processing operators. The standard expression format is ${Node code|Variable name}. For details about how to define an expression, see Table 2.

  • Node code: It is dynamically allocated by the system and cannot be changed. You can click a node in the API orchestration canvas to view the node code and click to copy the node code.
    Figure 1 Viewing the node code

  • Variable name: Supported variables include request parameter values and result set parameters. For details, see Table 2.
Table 2 Methods for defining an condition expression

Operator

Variable Expression

Example Value

Entry API

Obtain the value of the request parameter of the entry API: ${Node code|Input parameter name}.
NOTE:

This expression is supported for POST requests whose input parameters are located in Query, Header, Path, or Body.

If the node code of the entry API is EntryApi_3909f, and the input parameter userId is located in Path, set the expression for obtaining the value of the request parameter to ${EntryApi_3909f|userId}.

Common API

  1. Obtain the value of the request parameter of the common API: ${Node code|Input parameter name}.
    NOTE:

    This expression is supported for POST requests whose input parameters are located in Query, Header, Path, or Body.

  2. Obtain the result sets and related variables of common APIs:
    • ${Node code|payload.success}: checks whether the query status of a common API is successful. The result is true or false.
    • ${Node code|payload.rowSize}: obtains the number of rows in the query result set of a common API.
    • ${Node code|payload.columnSize}: obtains the number of columns in the query result set of a common API.
    • ${Node code|payload.columnNames}: obtains the column names in the query result set of a common API.
    • ${Node code|payload.data[n-1].id}: obtains the value of row n in the id column in the query result set of a common API.
  • If the node code of a common API is NormalApi_4246f, and the input parameter userId is located in Path, set the expression for obtaining the value of the request parameter to ${NormalApi_4246f|userId}.
  • If the node code of a common API is NormalApi_4246f, and the value is a one-dimensional array of multiple rows and a single column, set the expression for obtaining the values of the first row in the result set to ${NormalApi_4246f|payload.data[0]}.
  • If the node code of a common API is NormalApi_4246f, and the value is a two-dimensional array of multiple rows and columns, set the expression for obtaining the value in the first row and price column in the result set to ${NormalApi_4246f|payload.data[0].price}.

For example, if there are three sequential nodes, A (entry API), B (common API), and C (conditional branch), and node C needs to obtain the request parameter values of node A and the output values of node B:

  • If the code of node A is EntryApi_3909f, and the location of input parameter userId is Path, set the expression for obtaining the request parameter value of node A as follows:

    ${EntryApi_3909f|userId}

  • If the code of node B is NormalApi_4246f, and the value is a two-dimensional array of multiple rows and columns, set the expression for obtaining the value in the first row and name column in the result set of node B as follows:

    ${NormalApi_4246f|payload.data[0].name}