# Get workflow job import context

<span id="查询工作流作业导入上下文"></span>

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Read the import task run context associated with a workflow job, including the import task identifiers, run status, row count, and file counts. When the target job is not associated with an import task, the endpoint returns a successful response with `data.import_context` omitted; to inspect per-file statuses, continue with [List workflow job import files](list-workflow-job-import-files.md).

```text
GET https://api.moi.matrixorigin.cn/v5/workflow/v2/workflow-apps/{workflow_id}/executions/{execution_id}/import-context
```

<span id="调用前准备"></span>

## Before you begin

1. Prepare a [personal access token](../../../../../guides/genesis/api-keys.md#creating-and-managing-personal-access-tokens) with workflow job read permission and the [target workspace ID](../../../../../guides/ai-studio/resource-center/workspace.md#copy-the-workspace-id).
2. Obtain the workflow ID and job ID via [Start workflow job](start-workflow-job.md#successful-response) or [View workflow jobs](list-workflow-jobs.md#successful-response).

<span id="请求参数"></span>

## Request parameters

Replace `$AI_STUDIO_API_KEY`, `$WORKSPACE_ID`, `$WORKFLOW_ID`, and `$EXECUTION_ID` with actual values.

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

```bash
curl "https://api.moi.matrixorigin.cn/v5/workflow/v2/workflow-apps/$WORKFLOW_ID/executions/$EXECUTION_ID/import-context" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID"
```

:::::
:::::{tab-item} Parameters

### Path parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `workflow_id` | string | Yes | Workflow ID. When provided in the path, returns `404` if the target job does not belong to this workflow. |
| `execution_id` | string | Yes | Workflow job ID. |

When querying by `execution_id` without specifying `workflow_id`, call `GET https://api.moi.matrixorigin.cn/v5/workflow/v2/workflow-apps/executions/{execution_id}/import-context`.

:::::
::::::
:::::::

<span id="成功响应"></span>

## Successful response

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "import_context": {
      "task_id": "task-001",
      "task_name": "orders-import",
      "run_id": "run-001",
      "workflow_execution_id": "exec-001",
      "workflow_app_id": "wf-001",
      "moi_task_id": "mowl-task-001",
      "moi_case_id": "mowl-case-001",
      "status": 3,
      "row_count": 1200,
      "file_count": 4,
      "total": 4,
      "total_success": 4,
      "total_failed": 0,
      "started_at": "2026-08-28T10:00:00Z",
      "ended_at": "2026-08-28T10:02:15Z",
      "created_at": "2026-08-28T09:59:58Z"
    }
  }
}
```

:::::
:::::{tab-item} Fields

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` when the request succeeds. |
| `msg` | string | Response status message. |
| `data` | object | Returned payload for this call. Empty object `{}` when the job is not associated with an import task. |
| `data.import_context` | object | Associated import run context; omitted when the job is not linked to an import task. |
| `data.import_context.task_id` | string | Associated import task ID. |
| `data.import_context.task_name` | string | Import task name. |
| `data.import_context.run_id` | string | Import run record ID. Can be an empty string before a run record is created. |
| `data.import_context.workflow_execution_id` | string | Associated workflow job ID. |
| `data.import_context.workflow_app_id` | string | Associated workflow ID. |
| `data.import_context.moi_task_id` | string | Server task identifier. |
| `data.import_context.moi_case_id` | string | Server case identifier. |
| `data.import_context.status` | integer | Import run status code: `1` created, `2` running, `3` completed, `4` failed, `5` cancelled. |
| `data.import_context.error_message` | string | Import run error message; omitted when empty. |
| `data.import_context.row_count` | integer | Number of rows processed or written in this import run. |
| `data.import_context.file_count` | integer | File count recorded on the import run; `0` for structured load tasks. |
| `data.import_context.total` | integer | Total files counted across file statuses; `0` for structured load tasks. |
| `data.import_context.total_success` | integer | Number of successfully imported files; `0` for structured load tasks. |
| `data.import_context.total_failed` | integer | Number of failed import files; `0` for structured load tasks. |
| `data.import_context.started_at` | string | Start time in RFC 3339 format; omitted when not recorded. |
| `data.import_context.ended_at` | string | End time in RFC 3339 format; omitted when not recorded. |
| `data.import_context.created_at` | string | Creation time in RFC 3339 format; omitted when not recorded. |

:::::
::::::
:::::::

<span id="错误响应"></span>

## Error response

An error is returned when the target job does not exist, does not belong to the workflow specified in the path, or the current identity lacks permission to access the job. Verify the workspace ID, workflow ID, and job ID before retrying.

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": "ErrNotFound",
  "msg": "Not Found"
}
```

:::::
:::::{tab-item} Fields

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | Error code. |
| `msg` | string | Readable error message. |

:::::
::::::
:::::::

### Common HTTP errors

```{list-table}
:header-rows: 1

* - HTTP status
  - Error code
  - Common cause
  - Suggested action
* - 400
  - `ErrParamInvalid`, `ErrWorkspaceRequired`
  - The target workspace header is missing or the job identifier is empty.
  - Check the workspace header and path parameters.
* - 401
  - `Unauthorized`
  - Authentication credentials are missing or invalid.
  - Check that the personal access token is valid.
* - 403
  - `ErrForbidden`
  - The current identity cannot read the import context for this workflow job.
  - Use an authorized identity, or request access from an administrator.
* - 404
  - `ErrNotFound`
  - The job does not exist, or does not belong to the `workflow_id` specified in the path.
  - Verify `execution_id`, `workflow_id`, and the target workspace.
* - 500
  - `ErrServer`
  - Failed to read the associated import record or persisted status is invalid.
  - Retain the request details and recheck the job and import task states later.
* - 503
  - `ErrServiceUnavailable`
  - Authorization or storage dependencies are temporarily unavailable.
  - Retry the query later.
```
