Create custom operator¶
Create a custom operator that can be used in the workflow. Code type provides Python code or source files. Built-in binding types create binding configurations based on a workflow operator version.
POST $CLOUDSIGMA_API_BASE/workflow/v2/custom-operators
Before you call¶
Configure the CloudSigma regional endpoint and authentication before calling. The endpoint, credentials, workspace, and resource IDs must belong to the same region. Prepare personal access token and target workspace ID that can access the target workspace. Prepare content according to the type you want to create:
When creating a code type, prepare Python source code or source file IDs.
When creating a built-in binding type, first query workflow operator details and select the base operator version. Record the operator ID, version, and required binding configuration.
Request body¶
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": "文本计数",
"identifier": "text_counter",
"description": "统计输入文本的字符数。",
"language": "python",
"handler": "main.handle",
"input_schema": {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "要统计的文本。"
}
}
},
"output_schema": {
"type": "object",
"properties": {
"count": {
"type": "integer",
"description": "文本的字符数。"
}
}
},
"code": "def handle(workspace_id, sdk, input):\n return {\"count\": len(input[\"text\"])}"
}'
Code types need to provide code or source files, and built-in binding types need to specify a base operator. The two types of exclusive fields cannot be mixed. The code entry defaults to main.handle, and the enabled status defaults to true.
When the ID of the associated directory and database is less than or equal to 0, it will be ignored. When filling in the node ID, it must conform to the prefix format. Even if the suffix contains workspace information, it does not mean that the service has verified its ownership.
The service will check the root object of the input and output definition, and the relationship between type, properties, and required. The description attribute can be omitted.
The input attribute of the code operator cannot be empty, and the output properties can be omitted. When a built-in binding has no input mapping, an empty property object can be submitted. The JSON Schema will not be fully compiled on save, nor will the code be run.
Field |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
operator name. |
|
string |
Yes |
operator description. |
|
string or null |
No |
operator type. Code type when omitted. |
|
string or null |
No |
The implementation language of the code type. Currently only python is supported. |
|
string or null |
No |
Code type handler function. Python handler functions use module and function names, such as main.handle. The corresponding function must accept three parameters: workspace_id, sdk and input. |
|
string or null |
No |
operator version. When omitted, v1. |
|
string or null |
No |
Isolation configuration for code types. Currently only PUBLIC is supported. |
|
string or null |
No |
Source code for code types. Choose one from source_file_id. |
|
string or null |
No |
The source file ID of the code type. Choose one of two options: code. |
|
string or null |
Conditional |
The base operator ID of the built-in binding type. Required when selecting built-in binding. |
|
string or null |
Conditional |
The base operator version of the built-in binding type. Required when selecting built-in binding. |
|
string or null |
No |
Optional operator identifier. Must comply with the custom operator prefix format, and the suffix is not used to verify workspace ownership. |
|
string |
Yes |
operator identification. |
|
object or string |
Yes |
Enter the definition. Attributes need to declare the type, and the description can be omitted. The specific structure and type conditions are explained after the table. |
|
object or string |
Yes |
Output definition. Attributes need to declare the type, and the description can be omitted. The specific structure and type conditions are explained after the table. |
|
object or string |
No |
Binding configuration required for built-in binding types. |
|
integer or null |
No |
Associate Catalog ID. Non-positive values are ignored when created. 0 clears the association when updating, and negative numbers are invalid. |
|
integer or null |
No |
Associated database ID. Non-positive values are ignored when created. 0 clears the association when updating, and negative numbers are invalid. |
|
boolean or null |
No |
Whether to enable initially. |
Successful response¶
{
"code": "OK",
"msg": "OK",
"data": {
"id": 123,
"node_id": "moi:custom.operator:workspace:text_counter",
"name": "文本计数",
"identifier": "text_counter",
"description": "统计输入文本的字符数。",
"language": 1,
"handler": "main.handle",
"isolation_level": "PUBLIC",
"input_schema": "{\"type\":\"object\"}",
"output_schema": "{\"type\":\"object\"}",
"enabled": true,
"created_by": "user_01",
"updated_by": "user_01",
"kind": 1,
"catalog_id": 1,
"database_id": 2
}
}
Field |
Type |
Description |
|---|---|---|
|
string |
success code. |
|
string |
Response information. |
|
object |
The data returned by this operation. |
|
integer |
The new custom operator ID. |
|
string |
The operator ID in the workflow. |
|
string |
operator name. |
|
string |
operator identification. |
|
string |
operator description. |
|
integer |
operator implements language code. |
|
string |
Code type handler function. |
|
string |
operator version. |
|
string |
operator isolation configuration. |
|
string |
Source file ID. Returned when created from source file. |
|
string |
Enter the defined serialization content. |
|
string |
Outputs the serialized content of the definition. |
|
boolean |
Whether the operator is enabled. |
|
string |
Creator ID. |
|
string |
Last updated by identifier. |
|
integer |
Creation time. |
|
integer |
Last updated time. |
|
integer |
operator type code. |
|
string |
Association ID. |
|
string |
Base node version. |
|
string |
Extended configuration. |
|
integer |
The associated Catalog ID. |
|
integer |
The associated database ID. |
Error response¶
{
"code": "ErrParamInvalid",
"msg": "请求参数无效"
}
Field |
Type |
Required |
Description |
|---|---|---|---|
|
string |
No |
error code. |
|
string |
No |
Readable error message. |
Common HTTP errors¶
HTTP status |
Error code |
Common cause |
Recommended action |
|---|---|---|---|
400 |
|
Invalid request field, workspace, or operation precondition. |
Fix the request parameters and submit again. |
403 |
|
The current identity or active role does not have permission for this operation. |
Use an authorized identity or contact an administrator to grant access. |
404 |
|
The target object or required reference was not found. |
Verify the object identifier, workspace, and current status. |
409 |
|
Conflict in resource state, request payload, or concurrent modification. |
Re-read the current state and version, then handle according to the latest result. |
500 |
|
Internal processing failed; write operations may have been partially applied. |
Retain request and trace details, and verify the current state before retrying. |
503 |
|
A business, runtime, or authorization dependency is temporarily unavailable. |
After the dependency recovers, check existing results first instead of blindly repeating writes. |