> ## 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.

# 更新 Deployment

> 使用 merge-patch 语义部分更新已有 Deployment。

`POST /api/v1/cloud/deployments/{id}`

使用 merge-patch 语义更新 Deployment。请求体中包含的字段会被更新，未包含的字段保持不变。

<Note>
  本端点使用 `POST`（非 `PATCH`）以对齐 CMA 规范。仅提供的字段作为部分更新生效。
</Note>

## 路径参数

| 参数   | 类型     | 说明                       |
| ---- | ------ | ------------------------ |
| `id` | string | Deployment ID（`dep_` 前缀） |

## 请求头

| 头部              | 必选 | 说明                 |
| --------------- | -- | ------------------ |
| `Authorization` | 是  | `Bearer <PAT>`     |
| `Content-Type`  | 是  | `application/json` |

## 请求体

所有字段均为可选。只需包含要修改的字段。

| 字段                      | 类型              | 说明                                                                      |
| ----------------------- | --------------- | ----------------------------------------------------------------------- |
| `name`                  | string          | 新名称（最长 256 字符）                                                          |
| `description`           | string          | 新描述                                                                     |
| `agent`                 | string 或 object | 新 Agent 引用（字符串 ID 或 `{id, type, version}` 对象）。对象形式必须包含 `type: "agent"`。 |
| `environment_id`        | string          | 新 Environment ID                                                        |
| `schedule`              | object          | 更新调度配置（须包含全部子字段：`type`、`expression`、`timezone`）                         |
| `initial_events`        | array           | 新初始事件数组（1–50 个）                                                         |
| `resources`             | array           | 更新资源                                                                    |
| `vault_ids`             | array           | 更新 Vault ID 列表                                                          |
| `metadata`              | object 或 null   | Merge-patch 字符串元数据（key→string 更新，key→null 删除；传 `null` 清空全部 metadata）    |
| `environment_variables` | string 或 null   | 更新 Deployment 级环境变量；传 `null` 或空字符串清空。Self-hosted Environment 不支持        |

## 示例请求

```bash theme={null}
curl -X POST "https://api.qoder.com/api/v1/cloud/deployments/dep_019ec55a2b687b3f94eee77dd77e4b2a" \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "api-doc-verification-deployment-v2",
    "schedule": {
      "type": "cron",
      "expression": "30 9 * * 1-5",
      "timezone": "Asia/Shanghai"
    }
  }'
```

## 示例响应

**HTTP 200 OK**

返回更新后的完整 Deployment 对象。

```json theme={null}
{
  "agent": {
    "id": "agent_019ebb21ef8e7df6a559052c94875160",
    "type": "agent",
    "version": 1
  },
  "archived_at": null,
  "created_at": "2026-06-14T08:58:01Z",
  "description": "Deployment created for API documentation verification",
  "environment_id": "env_019e49a1780171daac1e6b01f290ac2b",
  "environment_variables": "",
  "id": "dep_019ec55a2b687b3f94eee77dd77e4b2a",
  "initial_events": [
    {
      "content": [
        {
          "type": "text",
          "text": "Generate today's status report"
        }
      ],
      "type": "user.message"
    }
  ],
  "metadata": {},
  "name": "api-doc-verification-deployment-v2",
  "paused_reason": null,
  "resources": [],
  "schedule": {
    "expression": "30 9 * * 1-5",
    "timezone": "Asia/Shanghai",
    "type": "cron",
    "upcoming_runs_at": [
      "2026-06-15T01:30:00Z",
      "2026-06-16T01:30:00Z",
      "2026-06-17T01:30:00Z",
      "2026-06-18T01:30:00Z",
      "2026-06-19T01:30:00Z"
    ]
  },
  "status": "active",
  "type": "deployment",
  "updated_at": "2026-06-14T08:58:11Z",
  "vault_ids": []
}
```

## 错误码

| HTTP | type                    | 触发条件                                                                                                                  |
| ---- | ----------------------- | --------------------------------------------------------------------------------------------------------------------- |
| 400  | `invalid_request_error` | 字段值无效、对象形式 `agent` 缺少 `type: "agent"`、名称为空、cron 表达式无效、metadata 或 environment\_variables 无效、或引用的 Agent/Environment 已归档 |
| 401  | `authentication_error`  | PAT 无效或过期                                                                                                             |
| 404  | `not_found_error`       | Deployment 不存在                                                                                                        |

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

## 相关

<CardGroup cols={2}>
  <Card title="获取 Deployment" icon="layer-group" href="/zh/cloud-agents/api/deployments/get">
    查看单个 Deployment 的详细信息。
  </Card>

  <Card title="暂停 Deployment" icon="pause" href="/zh/cloud-agents/api/deployments/pause">
    暂停调度但保留配置。
  </Card>

  <Card title="归档 Deployment" icon="archive" href="/zh/cloud-agents/api/deployments/archive">
    终止 Deployment 并停止所有调度。
  </Card>

  <Card title="错误参考" icon="circle-exclamation" href="/zh/cloud-agents/api/conventions/errors">
    所有 API 错误码与错误信封约定。
  </Card>
</CardGroup>
