Skip to content

Execute External Function



POST /api/v1/outer_function/execute

Overview

Execute a function that the central Func service allows to be called via OpenAPI.

Before You Call and Usage Steps

Use the API Key of the target workspace; routine.defaultAccess is required. First obtain the currently allowed content[].id from List Functions, read the description/definition/kwargsJSON to confirm the actual business effect, and then construct the real values for funcBody.kwargs. The example example__openapi.test applies only to deployments where that function actually exists in the current catalog; other deployments must replace it with the real ID and corresponding parameters. This is not an entry point for uploading arbitrary code.

The server verifies that the central Func contains a function matching category=openapi/id. Allowed results are cached by funcId (3600 seconds by default, which a site can override); removal from the catalog is not promised to invalidate old caches immediately. Before execution, workspace_uuid and workspace_token are automatically written into kwargs, overriding client values of the same name. There is no need to obtain or manually submit a reporting Token from other interfaces, and this cannot be used to switch workspaces. What is injected here is the workspace reporting Token, not DF-API-KEY; required business parameters and default values still follow the specific function definition.

A function may write data, trigger notifications, or perform other external operations. Confirm the side effects and idempotency of the target function before executing; do not treat this entry point as a read-only liveness probe. The interface does not guarantee that a timeout means the function was not executed; after a failure or timeout, first confirm the function's business result, then decide whether to retry. By default, the execution result is placed directly into content, and the SDK preserves the function's business failure body, so HTTP 200 with an outer success=true may still have content.ok=false. Clients must check the inner ok/error/reason and the data result according to the actual function, and must not judge only by the outer status.

returnType controls the Func return representation; the default is raw. Whether ALL/raw/repr/jsonDumps apply to the current function is subject to the Func service documentation. repr/jsonDumps data may be a string and must not be parsed as an object unconditionally. Additional diagnostic fields in the response may contain request parameters; handle them according to their actual content and do not forward bodies containing credentials publicly.

The historical SDK adaptation for the central Func list/pre-execution allowlist does not determine failure based solely on the upstream HTTP status: for JSON dictionaries, only ok=false or the numeric value 0 triggers a business error; a non-200 response with ok missing/true may still continue to fetch data; only a non-dictionary response with a non-200 HTTP status is definitively reported as an external function error. An empty catalog alone does not prove that the upstream service is connected properly; in case of anomalies, ask the administrator to check the service logs.

For more function information, see the Func documentation.

Request Headers

Parameter Type Required Description
DF-API-KEY string Y OpenAPI authentication credential for the workspace.
Example: <DF-API-KEY>
How to obtain or enter: Obtain an OpenAPI Key with this operation permission from the API Key management of the target workspace.

Body Request Parameters

Parameter Type Required Description
funcId string Y Required string. Must be a function visible in the openapi category of the central service or still in the allow cache; it is not an arbitrary local function/script name.
Allow null: False
Example: example__openapi.test
How to obtain or enter: Select the complete ID that is currently allowed and whose function you understand from content[].id in List Functions.
funcBody json Optional JSON object. Cannot be a string/array/null; if not provided, the call is made with an empty object and the workspace identity and Token are injected.
Allow null: False
Example: {"kwargs": {"your_name": "示例调用者"}, "options": {"returnType": "jsonDumps"}}
How to obtain or enter: Construct parameter values according to the function's description/definition metadata; when it can be omitted, workspace parameters are injected automatically.
funcBody.kwargs json Optional dynamic JSON object; positional args arrays are not exposed. workspace_uuid/workspace_token are forcibly overridden by the server.
Allow null: False
Example: {"your_name": "示例调用者"}
How to obtain or enter: Map function parameter names to real business values; for example, set your_name to a string rather than the {"default":...} definition object.
funcBody.options json Optional JSON object; this public declaration defines only returnType.
Allow null: False
Example: {"returnType": "jsonDumps"}
How to obtain or enter: Choose the return representation supported by that Func according to client needs.
funcBody.options.returnType custom_enum Optional custom_enum; the public enumeration is ALL/raw/repr/jsonDumps, and the default raw follows the Func service behavior; casing is subject to what the service actually accepts.
Allow null: False
Enum values: ['ALL', 'raw', 'repr', 'jsonDumps']
Example: jsonDumps
How to obtain or enter: Typically use raw to read the original result and jsonDumps for JSON text; first select according to the specific function documentation.

Request Example

curl --request POST 'https://openapi.truewatch.com/api/v1/outer_function/execute' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"funcId":"example__openapi.test","funcBody":{"kwargs":{"your_name":"示例调用者"},"options":{"returnType":"jsonDumps"}}}'

Response

HTTP 200, application/json. The example below shows the main fields that can be read directly.

Field Type Description
content JSON Carries the Func execution response as-is; usually an object containing ok/data. It varies by function/representation and is not a uniform successful business structure.
content.ok boolean Business execution success flag from the Func service; must be checked separately, since a failure may still return an outer HTTP 200.
content.data JSON Data returned by the function; its shape depends on the function and returnType. The example is illustrative only and does not guarantee a fixed result key.
content.error JSON Func business error value; may appear on failure. It is not the Studio outer errorCode.
content.reason string Func business failure classification; the actual value is determined by Func.
content.message JSON Func business message; different from the Studio top-level message.
content.detail JSON Func diagnostic information, such as the execution task ID; not guaranteed to be present every time.
content.traceId string Func upstream trace ID; may be present. The top-level traceId is the trace of this Studio call.
content.reqCost JSON Time cost information when provided by Func; the unit depends on the Func service version and Studio does not convert it.
content.reqTime JSON Request time when provided by Func.
content.respTime JSON Response time when provided by Func.
content.reqDump JSON Request diagnostic information when provided by Func; may contain actual parameters, so handle and store it according to its content.
content.declaration object or null Workspace public declaration for non-empty business objects; may be null or an empty object when not configured. It is not attached for empty business objects.
{
  "code": 200,
  "content": {
    "ok": true,
    "data": {
      "result": "示例调用结果"
    },
    "declaration": {}
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Illustration of a function business failure where the Studio interface still succeeds at the outer level:

{
  "code": 200,
  "content": {
    "ok": false,
    "error": 599.3,
    "reason": "EFuncFailed",
    "message": "Calling Function failed",
    "detail": {
      "id": "FUNC-TASK-EXAMPLE"
    },
    "declaration": {}
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Error Responses

For authentication, rate limiting, and common request errors, see Common Error Definitions.

This page distinguishes Studio parameter/permission/connection errors from internal Func business failures. Func business errors are not exhaustively listed; the HTTP 200 example with content.ok=false only illustrates the wrapping boundary, and the specific error/reason is determined by the actual function.

HTTP Status errorCode Trigger Condition Message or Response Description Handling
406 ft.ParameterValidationFailed A request field is missing, or a field value violates the declared validation conditions Parameter parsing failed Check the parameter location, field name, type, and value.
400 ft.RequestJsonFormatError The request JSON syntax is invalid Request JSON format error Fix the JSON according to content.reason, line, and column.
400 ft.JsonFormatError The request body is not a JSON object Some json file format error Submit funcId and an optional funcBody object.
403 ft.Forbidden The target function is not in the central openapi catalog and has no allow cache, or the workspace Token access context does not permit it You do not have permission to perform this operation Reselect the complete ID from the current catalog; do not treat a local function name as an allowed function.
404 ft.WKSPTokenNotExist The current workspace has no available reporting Token Token does not exist in the workspace Ask the administrator to check the workspace Token configuration; do not bypass this by passing a forged workspace_token.
400 ft.OuterFuncFailed The pre-execution allowlist returns a dictionary with ok=false (special reasons are mapped separately), or a non-dictionary response with a non-200 HTTP status External function call failed Check the central service and the target function; business failures in the actual execution phase are usually checked inside content.
500 ft.InternalServerError Connection timeout, invalid JSON/non-JSON body that cannot be wrapped, workspace Token storage anomaly, or other uncaught errors Internal error First check whether the target function has already completed its business action, retain the traceId and actual Func task information, and then decide whether to retry.
400 ft.SameSetTraggerExists The central Func list/allowlist returns ok=false with reason EBizCondition.DuplicatedCrontabConfig A trigger with the same configuration already exists This is a shared-SDK-specific error mapping; check the actual upstream response and configuration, and do not conclude from this page's request alone that the function does not exist.