# 查询标签导出任务及下载文件

查询标签导出任务的状态（pending/running/succeeded/failed/expired/unknown）和下载文件，按 poll_after_seconds 轮询原任务。只有 succeeded 时 files 才是完成结果；文件链接带临时凭证。

## 请求

```text
POST https://open.cli.im/api/v2/rpc/labelExports/get
```

| 项目 | 要求 |
|---|---|
| 最低权限 | 读写，见[权限档位](https://cli.im/open-api/openapi/v2/auth.md#org-policy) |
| 需要的 scope | `qrcodes.write` |
| 组织 Key | 不能调用，返回 403 `credential_type_not_allowed`，见[历史组织 Key](https://cli.im/open-api/openapi/v2/auth.md#org-key) |

相关调用流程：[导出可打印的标签](https://cli.im/open-api/openapi/v2/scenarios/export-labels.md)。

## 请求参数

请求体为 JSON。

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `task_id` | string | 是 | labelExports/create 返回的任务 ID。最长 128 个字符 |

## 请求示例

示例里的 ID、幂等键等换成实际值。

```bash
curl -sS -X POST 'https://open.cli.im/api/v2/rpc/labelExports/get' \
  -H "Authorization: Bearer ${CAOLIAO_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
  "task_id": "label_560012"
}'
```

## 响应

成功时 HTTP 状态码为 200，顶层 `code` 为 `0`，结果在 `data` 里。失败时的返回见[错误码与调用额度](https://cli.im/open-api/openapi/v2/error-codes.md)和[业务错误码](https://cli.im/open-api/openapi/v2/error-catalog.md)。

| 字段 | 类型 | 一定返回 | 说明 |
|---|---|---|---|
| `data.task_id` | string | 是 | 导出任务 ID |
| `data.status` | string | 是 | pending 排队中；running 生成中；succeeded 已完成；failed 失败；expired 文件已过期；unknown 结果未能确认。可选值：`pending`、`running`、`succeeded`、`failed`、`expired`、`unknown` |
| `data.accepted_count` | integer | 是 | 已受理的码数量 |
| `data.exported_count` | integer | 是 | 实际导出的码数量；未能确认时为 null |
| `data.format` | string | 是 | 导出格式 |
| `data.files` | object[] | 是 | 导出文件。只有 status 为 succeeded 时可作为完成结果 |
| `data.files[].url` | string | 是 | 下载地址，带临时凭证，不要记录或公开 |
| `data.files[].format` | string | 是 | 导出格式 |
| `data.files[].container` | string | 是 | 文件容器，固定为 zip |
| `data.expires_at` | integer | 是 | 文件过期时间（Unix 秒） |
| `data.receipt_expires_at` | integer | 是 | 任务回执的过期时间（Unix 秒） |
| `data.poll_after_seconds` | integer | 是 | 建议的轮询间隔（秒）；任务已结束时为 null |
| `data.warnings` | string[] | 否 | status 为 unknown 时的提示 |
| `data.error_code` | string | 否 | status 为 failed 时的原因码 |

### 响应示例

```json
{
  "code": 0,
  "message": "ok",
  "data": {
    "task_id": "label_560012",
    "status": "succeeded",
    "accepted_count": 1,
    "exported_count": 1,
    "format": "png_zip",
    "files": [
      {
        "url": "https://ncstatic.clewm.net/label/export/example.zip?sign=EXAMPLE",
        "format": "png_zip",
        "container": "zip"
      }
    ],
    "expires_at": 1795604800,
    "receipt_expires_at": 1795086400,
    "poll_after_seconds": null
  }
}
```

## 常见错误

`TASK_NOT_FOUND`、`TASK_RECEIPT_EXPIRED`。含义和处理方式见[业务错误码](https://cli.im/open-api/openapi/v2/error-catalog.md)。

---

本页由 [openapi.json](https://cli.im/open-api/openapi/v2/overview.md#%E6%8E%A5%E5%8F%A3%E8%A7%84%E8%8C%83-openapi-json) 生成。全部接口见[接口清单](https://cli.im/open-api/openapi/v2/api-index.md)。
