> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qoder.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 列出 Work

> 列出 self-hosted Environment 下的 work items。

`GET /api/v1/cloud/environments/{environment_id}/work`

列出 `self_hosted` Environment 下的 work items。结果使用游标分页，并按 ID 升序返回；该顺序等同于队列创建顺序。

## 路径参数

| 参数               | 类型     | 说明                        |
| ---------------- | ------ | ------------------------- |
| `environment_id` | string | Environment ID，前缀为 `env_` |

## 请求头

| 头部              | 必选 | 说明                  |
| --------------- | -- | ------------------- |
| `Authorization` | 是  | `Bearer $QODER_PAT` |

## 查询参数

| 参数          | 类型      | 必选 | 默认值 | 说明                             |
| ----------- | ------- | -- | --- | ------------------------------ |
| `limit`     | integer | 否  | 20  | 每页返回数量，必须为正整数；超过 100 时按 100 处理 |
| `page`      | string  | 否  | -   | 上一次响应 `next_page` 返回的游标        |
| `before_id` | string  | 否  | -   | 返回该 work item ID 之前的记录         |
| `after_id`  | string  | 否  | -   | 返回该 work item ID 之后的记录         |

`page`、`before_id` 和 `after_id` 不能同时使用。完整分页规范详见 [分页](/zh/cloud-agents/api/conventions/pagination)。

## 示例请求

```bash theme={null}
curl -X GET "https://api.qoder.com/api/v1/cloud/environments/env_019e64e01a137caf953ac2ac7b42ec5c/work?limit=2" \
  -H "Authorization: Bearer $QODER_PAT"
```

## 示例响应

**HTTP 200 OK**

```json theme={null}
{
  "data": [
    {
      "id": "work_019f3be4fd2475d9a784bf2c739e1194",
      "type": "work",
      "environment_id": "env_019e64e01a137caf953ac2ac7b42ec5c",
      "data": {
        "type": "session",
        "id": "sess_019f3be3fa66750bb9a1fbcde85b5fe1"
      },
      "state": "queued",
      "created_at": "2026-07-01T08:15:01Z",
      "acknowledged_at": null,
      "started_at": null,
      "latest_heartbeat_at": null,
      "stop_requested_at": null,
      "stopped_at": null,
      "metadata": {
        "job": "daily-report"
      }
    }
  ],
  "first_id": "work_019f3be4fd2475d9a784bf2c739e1194",
  "last_id": "work_019f3be4fd2475d9a784bf2c739e1194",
  "has_more": false,
  "next_page": null
}
```

## 响应字段

| 字段          | 类型                                                                            | 说明                                               |
| ----------- | ----------------------------------------------------------------------------- | ------------------------------------------------ |
| `data`      | [Work item 对象](/zh/cloud-agents/api/environments/work/schemas#work-item-对象)数组 | 当前页的 work items                                  |
| `first_id`  | string\|null                                                                  | 当前页第一条记录的 ID                                     |
| `last_id`   | string\|null                                                                  | 当前页最后一条记录的 ID                                    |
| `has_more`  | boolean                                                                       | 是否还有更多数据                                         |
| `next_page` | string\|null                                                                  | 下一页游标。`has_more` 为 true 时等于 `last_id`，否则为 `null` |

## 错误码

| HTTP | type                    | 触发条件                                       |
| ---- | ----------------------- | ------------------------------------------ |
| 400  | `invalid_request_error` | `limit` 不是正整数                              |
| 400  | `invalid_request_error` | 同时传入了 `page`、`before_id`、`after_id` 中的多个参数 |
| 400  | `invalid_request_error` | Environment 不是 `self_hosted`               |
| 401  | `authentication_error`  | PAT 无效或过期                                  |
| 403  | `permission_error`      | 无权限执行此操作                                   |
| 404  | `not_found_error`       | Environment 不存在                            |

完整错误信封格式见 [错误参考](/zh/cloud-agents/api/conventions/errors)。

## 相关

<CardGroup cols={2}>
  <Card title="云端环境" icon="server" href="/zh/cloud-agents/environments">
    选择 Agent 运行的容器、网络与依赖。
  </Card>
</CardGroup>
