Create custom operator

Create a custom operator that can be used in workflows. Code type operators require source code or source file IDs; built-in binding types use base operators and binding configurations.

HTTP
POST $CLOUDSIGMA_API_BASE/workflow/v2/custom-operators

Before you call this API

Configure the regional API endpoint and authentication, and select the target workspace.

First decide whether to create a code type or a built-in binding type, and prepare the corresponding implementation content.

Request

Shell
curl -X POST "$CLOUDSIGMA_API_BASE/workflow/v2/custom-operators" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Text Counter",
    "identifier": "text_counter",
    "node_id": "moi:custom.operator:$WORKSPACE_ID:text_counter",
    "description": "Counts the number of characters in the input text.",
    "language": "python",
    "handler": "main.handle",
    "input_schema": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string",
          "description": "The text to count."
        }
      }
    },
    "output_schema": {
      "type": "object",
      "properties": {
        "count": {
          "type": "integer",
          "description": "Character count."
        }
      }
    },
    "code": "def handle(workspace_id, sdk, input):\n    return {\"count\": len(input[\"text\"])}"
  }'

Request body

ParameterTypeRequiredDescription
namestringRequiredOperator name.
identifierstringRequiredOperator ID.
descriptionstringRequiredOperator description.
kindstringOperator type; when omitted, it is the code type.
languagestringThe implementation language of the code type; currently only python is supported.
handlerstringHandler for the code type. Python processing functions use module and function names, such as main.handle; the corresponding function must accept three parameters: workspace_id, sdk and input.
input_schemaobjectRequiredInput definition. description must be provided for each properties entry.
output_schemaobjectRequiredOutput definition. description must be provided for each properties entry.
versionstringVersion for the code type.
isolation_levelstringIsolation configuration for the code type.
codestringSource code for the code type; provide it instead of source_file_id.
source_file_idstringSource file ID for the code type; provide it instead of code.
base_node_idstringBase operator ID required by the built-in binding type.
base_node_versionstringBase operator version required by the built-in binding type.
binding_configobjectBinding configuration required by the built-in binding type.
node_idstringCustom workflow operator ID. When omitted, the service generates it from the target workspace and identifier.
enabledbooleanWhether to enable initially.
catalog_idintegerAssociated catalog ID.
database_idintegerAssociated database ID.

Successful response

The response returns the ID and configuration of the newly created operator. Save the operator ID, which will be used for subsequent viewing, updating, trial running, activation, deactivation, and deletion.

The response fields are as follows.

JSON
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "id": 123,
    "node_id": "moi:custom.operator:workspace:text_counter",
    "name": "Text Counter",
    "identifier": "text_counter",
    "language": 1,
    "kind": 1,
    "input_schema": "{\"type\":\"object\"}",
    "output_schema": "{\"type\":\"object\"}",
    "enabled": true
  }
}
FieldTypeDescription
codestringOK on success.
msgstringOK on success.
data.idintegerNewly created custom operator ID.
data.node_idstringOperator ID in the workflow.
data.namestringOperator name.
data.identifierstringOperator ID.
data.descriptionstringOperator description; returned if there is a value.
data.languageintegerImplements the numerical encoding of the language. language usage string in request.
data.kindintegerNumeric encoding of the operator type. kind usage string in request.
data.handlerstringProcessing function; returned when there is a value.
data.versionstringOperator version; returned if there is a value.
data.isolation_levelstringIsolation configuration; returned if there is a value.
data.source_file_idstringSource file ID; returned when created using a source file.
data.input_schemastringEnter the defined serialization content.
data.output_schemastringOutput the defined serialized content.
data.created_bystringCreator ID; returned if there is a value.
data.updated_bystringLast updater ID; returned if there is a value.
data.created_atintegerCreation timestamp; returned if there is a value.
data.updated_atintegerLast updated timestamp; returned if there is a value.
data.base_node_idstringThe basic operator associated with the built-in binding type; returned when there is a value.
data.base_node_versionstringThe basic operator version associated with the built-in binding type; returned when there is a value.
data.binding_configstringThe serialized content of the binding configuration; returned if there is a value.
data.catalog_idintegerAssociated Catalog ID; returned if there is a value.
data.database_idintegerThe associated database ID; returned if there is a value.
data.enabledbooleanWhether the operator is enabled.

Error response

JSON
{
  "code": "ErrParamInvalid",
  "msg": "请求参数无效",
  "data": null
}
FieldTypeDescription
codestringError code.
msgstringReadable error message.
datanull`null` in an error response.

Follow-up operations

Query custom operator details or Trial run custom operator.

Last updated on