> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# flowExecute

> 以调用 Flow API 的方式通过从触发端口到终结端口的完整工作流处理消息，并且必须通过管理员 API 用户和 authtoken 调用。

以与 [Flow API](../../flows/flow-api) 相同的方式处理工作流。这意味着单个消息将作为一个连续过程在多个端口中进行处理。允许调用一个以触发（Trigger）端口开始并以终结（Terminal）端口结束的完整工作流。

必须使用管理员 API 用户和 authtoken 通过 `connector.rsc/flowexecute` 端点调用此操作。

## 必选参数

* **connectorId**：工作流中第一个端口的 ID。

## 可选参数

* **WorkspaceId**：工作流所在 [工作区](../../flows/workspaces) 的 ID。如果未指定，操作将使用默认（Default）工作区。
* **MessageData**：作为 UTF-8 文本的输入消息数据。
* **MessageName**：输入消息的文件名。
* **HeaderName#**：要包含在消息中的消息头名称列表（以逗号分隔）。
* **HeaderValue#**：要包含在消息中的消息头值列表（以逗号分隔）。
* **InputEncoding**：输入消息数据的格式。可用值为 **UTF-8**、**BASE64** 和 **HEX**。默认值为 UTF-8。
* **OutputEncoding**：输出消息数据的格式。可用值为 **UTF-8**、**BASE64** 和 **HEX**。默认值为 UTF-8。

## 输出参数

* **Result**：结果。可用值为：**Success**、**Error**、**Warning**、**Pending** 和 **Skipped**。
* **MessageData**：如果 **Result** 不是 Error、Pending 或 Skipped，则为 UTF-8 格式的输出消息数据。
* **MessageName**：输出消息的文件名。
* **ErrorMessage**：如果 **Result** 为 Error 或 Warning，则为详细的错误信息。
* **LastConnectorId**：工作流中最后一个端口的 ID。
* **LastWorkspaceId**：工作流中最后一个工作区的 ID。
* **MessageId**：消息 ID。

## 示例

此示例显示了在 [ArcScript](../../connectors/script) 端口（触发端口）中此操作可用的输入和输出。它通过指定端口 ID 和所在的工作区来定义工作流中的第一个端口。它还定义了通过工作流处理的文件名及其内容。最后，使用管理员 API 用户和 authtoken 通过 `connector.rsc/flowexecute` 端点调用 `flowExecute` 操作。

```xml theme={null}
<!--Required:Define first connector in the flow--> 
<arc:set attr="flow.connectorid" value="Script_ChangeName"/> 
<!--Define workspace where flow is located, if not set this uses the Default workspace--> 
<arc:set attr="flow.workspaceid" value="Default"/> 
<!--Set filename of file to pass through flow as messagename attribute--> 
<arc:set attr="flow.messagename" value="[Filename]"/> 
<!--Get contents of message to pass to flow and set as messagedata attribute--> 
<!--Note this loads the contents of the file as a string--> 
<arc:set attr="in.file" value="[Filepath]" /> 
<arc:call op="fileRead" in="in" out="out" > 
  <arc:set attr="flow.messagedata" value="[out.file:data]" /> 
</arc:call> 

<!--Set a header and its value preserving the original filename, to reference later--> 
<arc:set attr="flow.headername#1" value="origfilename"/> 
<arc:set attr="flow.headervalue#1" value="[Filename]"/> 

<!--You must call this operation through connector.rsc and pass in a valid authtoken -->
<arc:call op="connector.rsc/flowExecute" authtoken="test:0d1V7j2r2Z7a9z1Y6z8y" in="flow" out="status"> 
  <!-- This if statement checks if the message encountered an error during processing. If yes, the message is finalized as Error in this script.--> 
  <arc:if exp="[status.result | equals('Error')]" >
    <arc:throw code="FlowFailed" desc="The message failed to be processed by the flowExecute call due to the following error: [status.ErrorMessage | def]" /> 
  </arc:if>
</arc:call>  
```
