# 查询任务详情

读取一个导入任务的定义和当前状态。创建、暂停、恢复或重试后，都使用此接口确认任务是否进入预期状态。

```text
GET https://moi.matrixorigin.cn/newmoi/task/get?task_id=$TASK_ID
```

## 调用前准备

准备有目标工作区访问权限的个人访问令牌、目标工作区 ID 和任务 ID。

下方示例使用：

- `$AI_STUDIO_API_KEY`：实际个人访问令牌，通过 `X-API-Key` Header 传递。
- `$WORKSPACE_ID`：要查询的工作区 ID，通过 `X-Workspace-ID` Header 传递。
- `$TASK_ID`：创建任务响应中的 `data.task_id`。

## 查询参数

| 参数 | 类型 | 是否必填 | 说明 |
| --- | --- | --- | --- |
| `task_id` | string | 是 | 要查询的导入任务 ID。 |

## 请求示例

```bash
curl "https://moi.matrixorigin.cn/newmoi/task/get?task_id=$TASK_ID" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID"
```

## 成功响应

成功时返回 `200`。

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "task": {
      "id": "task_01",
      "name": "import_orders",
      "config_type": 1,
      "source_connector_id": "conn_01",
      "connector_name": "orders_mysql",
      "volume_id": "vol_01",
      "status": 2,
      "total_rows": 100,
      "imported_rows": 100,
      "success_file_count": 1,
      "failed_file_count": 0,
      "latest_rows": {
        "read_rows": 100,
        "succeeded_rows": 100,
        "failed_rows": 0,
        "complete": true
      },
      "error_code": "",
      "error_summary": ""
    }
  }
}
```

响应字段如下。

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `code` | string | 成功时为 `OK`。 |
| `msg` | string | 成功时为 `OK`。 |
| `data.task` | object | 任务定义和当前处理状态。该对象的每个字段见[导入任务对象字段](import-task-object-fields.md)。 |

## 错误响应

```json
{
  "code": "ErrServer",
  "msg": "server error",
  "data": null
}
```

### 常见 HTTP 错误

```{list-table}
:header-rows: 1
:widths: 12 25 30 33

* - HTTP 状态码
  - 错误代码
  - 常见原因
  - 建议操作
* - `200`
  - `ErrServer`
  - 任务不存在、不可读取，或服务未能查询任务。
  - 同时检查 HTTP 状态和 `code`，并确认 `task_id` 与授权。
```

## 后续操作

用任务 ID [查询任务文件](list-import-task-files.md)查看文件级结果，或[查询运行记录](list-import-task-runs.md)查看历次运行。失败文件较多时，将失败文件的 `id` 交给[重试失败文件](retry-failed-import-files.md)。
