Skip to content

获取工作流运行结果

🔍 查询执行结果

此接口用于查询工作流的执行状态和结果。支持查询异步执行的工作流进度。

接口描述

根据执行 ID 获取工作流的运行状态和结果。可以查询执行中、已完成或失败的工作流信息。

请求方式

GET https://newapi.iflyrpa.com/api/rpa-openapi/executions/{executionId}

认证要求

需要带 BEARER KEY

请在请求头中添加:

Authorization: Bearer {YOUR_API_KEY}

路径参数

参数名类型必填说明
executionIdString工作流执行 ID,由执行接口返回

响应格式

成功响应 (HTTP 200)

json
{
  "code": "0000",
  "msg": "",
  "data": {
    "execution": {
      "id": "2acef765-795d-467e-bc5a-e5e8d313b56c",
      "project_id": "1966016474983485440",
      "status": "PENDING",
      "parameters": {},
      "result": null,
      "error": null,
      "exec_position": "EXECUTOR",
      "version": 8,
      "user_id": "a6a60f75-626a-4ba0-bd7e-799c8404aa6b",
      "start_time": "2025-09-11T13:52:41",
      "end_time": null
    }
  }
}

响应字段说明

顶层字段

字段名类型说明
codeString响应代码,"0000" 表示成功
msgString响应消息
dataObject返回的数据对象

data 字段

字段名类型说明
executionObject工作流执行信息对象

execution 字段

字段名类型说明
idString执行 ID
project_idString工作流项目 ID
statusString执行状态,可选值:
- PENDING 运行中
- COMPLETED 已完成
- FAILED 失败
parametersObject工作流输入参数
resultObject执行结果,格式取决于工作流定义
errorString错误信息,仅在失败时有值
exec_positionString执行位置
versionInteger工作流版本号
user_idString执行用户 ID
start_timeString开始时间(ISO 8601 格式)
end_timeString结束时间(ISO 8601 格式),运行中时为 null

状态示例

示例 1:运行中(PENDING)

json
{
  "code": "0000",
  "msg": "",
  "data": {
    "execution": {
      "id": "2acef765-795d-467e-bc5a-e5e8d313b56c",
      "project_id": "1966016474983485440",
      "status": "PENDING",
      "parameters": {},
      "result": null,
      "error": null,
      "exec_position": "EXECUTOR",
      "version": 8,
      "user_id": "a6a60f75-626a-4ba0-bd7e-799c8404aa6b",
      "start_time": "2025-09-11T13:52:41",
      "end_time": null
    }
  }
}

示例 2:已完成(COMPLETED)

json
{
  "code": "0000",
  "msg": "",
  "data": {
    "execution": {
      "id": "091e9d76-573e-4e8b-9037-06d91170091f",
      "project_id": "1965981379635499008",
      "status": "COMPLETED",
      "parameters": {
        "content": "调用"
      },
      "result": {
        "code": "0000",
        "msg": "启动成功",
        "data": {
          "number": 123
        }
      },
      "error": null,
      "exec_position": "EXECUTOR",
      "version": 8,
      "user_id": "a6a60f75-626a-4ba0-bd7e-799c8404aa6b",
      "start_time": "2025-09-11T13:46:48",
      "end_time": "2025-09-11T05:46:52"
    }
  }
}

示例 3:失败(FAILED)

json
{
  "code": "0000",
  "msg": "",
  "data": {
    "execution": {
      "id": "d11482bf-24c5-47f6-a42f-36f67043fec7",
      "project_id": "1972635107658616832",
      "status": "FAILED",
      "parameters": {},
      "result": {
        "code": "5001",
        "msg": "执行错误 工程数据异常",
        "data": null
      },
      "error": null,
      "exec_position": "EXECUTOR",
      "version": 8,
      "user_id": "ae1e0c83-4f05-4ad1-81a9-e7adc31a0b59",
      "start_time": "2025-10-13T14:33:49",
      "end_time": "2025-10-13T06:33:54"
    }
  }
}

说明

  • 异步执行的工作流使用此接口查询执行状态和结果
  • 状态为 PENDING 表示工作流仍在运行,可继续轮询查询
  • 状态为 COMPLETED 时,result 字段包含工作流的输出结果
  • 状态为 FAILED 时,result 字段包含执行器返回的错误信息
  • end_time 为 null 表示工作流仍在执行中
  • 建议使用轮询方式查询执行结果,每次查询间隔建议为 5-10 秒

错误信息说明

错误来源字段位置说明
执行器错误result.msg工作流执行器返回的错误信息,表示工作流逻辑执行失败
服务端错误error 字段服务端返回的错误信息,表示 API 调用或系统层面的错误

代码示例

cURL

bash
curl -X GET "https://newapi.iflyrpa.com/api/rpa-openapi/executions/2acef765-795d-467e-bc5a-e5e8d313b56c" \
  -H "Authorization: Bearer {YOUR_API_KEY}"

Python

python
import requests

execution_id = "2acef765-795d-467e-bc5a-e5e8d313b56c"
url = f"https://newapi.iflyrpa.com/api/rpa-openapi/executions/{execution_id}"
headers = {
    "Authorization": "Bearer {YOUR_API_KEY}"
}

response = requests.get(url, headers=headers)
result = response.json()
print(result)

# 获取执行状态
execution = result['data']['execution']
status = execution['status']
print(f"执行状态: {status}")

if status == "COMPLETED":
    print(f"执行结果: {execution['result']}")
elif status == "FAILED":
    print(f"执行错误: {execution['result']}")
elif status == "PENDING":
    print("工作流运行中...")

JavaScript

javascript
const apiKey = "{YOUR_API_KEY}";
const executionId = "2acef765-795d-467e-bc5a-e5e8d313b56c";
const url = `https://newapi.iflyrpa.com/api/rpa-openapi/executions/${executionId}`;

fetch(url, {
  method: "GET",
  headers: {
    "Authorization": `Bearer ${apiKey}`
  }
})
  .then(response => response.json())
  .then(result => {
    console.log(result);
    
    const execution = result.data.execution;
    const status = execution.status;
    
    console.log(`执行状态: ${status}`);
    
    if (status === "COMPLETED") {
      console.log(`执行结果:`, execution.result);
    } else if (status === "FAILED") {
      console.log(`执行错误:`, execution.result);
    } else if (status === "PENDING") {
      console.log("工作流运行中...");
    }
  })
  .catch(error => console.error("Error:", error));

轮询示例(Python)

python
import requests
import time

execution_id = "2acef765-795d-467e-bc5a-e5e8d313b56c"
url = f"https://newapi.iflyrpa.com/api/rpa-openapi/executions/{execution_id}"
headers = {
    "Authorization": "Bearer {YOUR_API_KEY}"
}

# 轮询获取结果
max_attempts = 60  # 最多查询 60 次
attempt = 0

while attempt < max_attempts:
    response = requests.get(url, headers=headers)
    result = response.json()
    execution = result['data']['execution']
    status = execution['status']
    
    print(f"查询 {attempt + 1}: 状态 = {status}")
    
    if status == "COMPLETED":
        print("✓ 工作流已完成")
        print(f"结果: {execution['result']}")
        break
    elif status == "FAILED":
        print("✗ 工作流执行失败")
        print(f"错误: {execution['result']}")
        break
    else:
        print("⏳ 工作流运行中,5 秒后重新查询...")
        time.sleep(5)
    
    attempt += 1

if attempt >= max_attempts:
    print("⚠ 查询超时")