> ## 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>  
```
