Invoke operator API service¶
Call the published and enabled operator API service. The fields of payload must conform to the input definition of the service; first View Service Configuration confirms that the service can be called and obtains the input definition.
POST https://moi.matrixorigin.cn/newmoi/workflow/v2/workitems/catalog/$NODE_ID/api-service/invoke
Preparation before calling¶
First View Service Configuration, confirm that the service is enabled, and obtain the operator ID, version and service name of the service to be called. Prepare the personal access token, target workspace ID, operator ID, version, and service name that has access to the target workspace.
Request body¶
node_idstringRequired- The ID of the operator to be called.
service_namestringRequired- Service name, using data.service.service_name from the service configuration response.
typestringRequired- Fixed to operator.
versionstringRequired- The published operator version.
payloadobject- the input data of the service; fields and types are subject to data.service.input_schema.
Request example
curl -X POST "https://moi.matrixorigin.cn/newmoi/workflow/v2/workitems/catalog/$NODE_ID/api-service/invoke" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H 'Content-Type: application/json' \
-d "{
\"service_name\": \"$SERVICE_NAME\",
\"type\": \"operator\",
\"version\": \"$VERSION\",
\"payload\": {
\"sql\": \"SELECT now()\"
}
}"
Successful response¶
data.result returns the status and operator output of this call. result is returned as a JSON format string; the operator output is read after parsing the string. When error appears in the response, handle it as an error message.
The response fields are as follows.
codestring- OK on success.
msgstring- OK on success.
data.result.case_idstring- ID of this call; can be used to correlate this result when the response is provided.
data.result.statusstring- The status returned by the service; occurs when the response is provided.
data.result.resultstring- JSON format string returned by the service; the parsed structure is determined by the operator.
data.result.errorstring- Error message returned by the service; appears when there is an error.
Successful response example
{
"code": "OK",
"msg": "OK",
"data": {
"result": {
"case_id": "case_01JEX4A1M2",
"status": "COMPLETED",
"result": "{\"count\":9}"
}
}
}
Error response¶
codestring- Error code.
msgstring- Readable error message.
datanull- `null` in an error response.
Error response example
{
"code": "api_service_unavailable",
"msg": "服务暂不可用",
"data": null
}
Follow-up operations¶
After the call is completed, when you need to check the configuration View operator API service configuration.