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

# 冻结 Build 快照

> 把当前草稿内容冻结成不可变快照，作为调试运行和发布的对象。

## 端点

```
POST https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/builds
```

认证：需要 API Key，且仅 App 作者（发布者本人）可调用；其他人得到 `404`。

把当前工作区内容冻结成不可变快照，是调试运行与发布的引用对象。

前置条件：工作区存在且当前内容有效（否则 `422` 并附 `issues`）；请求体可带 `expected_revision`（保存与冻结之间被并发修改则 `409`）。已有同一 `content_hash` 的就绪快照时直接复用，不产生重复行。api 型立即就绪；code 型返回 `202` 并提交镜像构建，同一 App 已有构建在进行时再次提交为 `409`。已弃用的 App 仍可构建，被拒绝的只是新的 Release。

## 请求

### 路径参数

<ParamField path="app_id" type="string" required>
  App 引用。
</ParamField>

### 请求体

<ParamField body="expected_revision" type="integer">
  期望的当前草稿版本号，不一致则 `409`。
</ParamField>

### 示例请求

```bash theme={null}
curl -X POST \
  -H "Authorization: Bearer $BAZHUAYU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"expected_revision": 3}' \
  "https://api-datahub.bazhuayu.com/v1/data-apps/carol/reviews-query/builds"
```

## 响应

### 200 成功

```json theme={null}
{
  "data": {
    "build_id": "string",
    "build_status": "string",
    "content_hash": "string",
    "source_revision": 0,
    "reused": false,
    "created_at": "string"
  }
}
```

响应包在 `data` 字段中，其内容如下。

<ResponseField name="build_id" type="string" required>
  Build 标识。
</ResponseField>

<ResponseField name="build_status" type="string" required>
  `ready` 就绪，`building` 构建中（code 型），`failed` 失败。
</ResponseField>

<ResponseField name="content_hash" type="string" required>
  内容哈希。
</ResponseField>

<ResponseField name="source_revision" type="integer" required>
  冻结时的草稿版本号。
</ResponseField>

<ResponseField name="reused" type="boolean">
  是否复用了已有的同内容快照。
</ResponseField>

<ResponseField name="created_at" type="string">
  创建时间。
</ResponseField>

### 错误

| HTTP | `code` | `category` | 说明 |
| - | - | - | - |
| 401 | `unauthorized` | `forbidden` | 缺少或无效的 API Key。 |
| 404 | `workspace-not-found` | `not_found` | 该 App 没有进行中的草稿。这是主路径上的正常状态，不是故障。 |
| 422 | `build-failed` | `invalid_input` | 工作区内容未通过校验，`issues[]` 列出问题。 |
| 409 | `revision-conflict` | `invalid_input` | `expected_revision` 与当前草稿版本号不一致，说明有并发修改。 |

错误响应统一为 `{"error": {code, category, message, retryable}}`，见<a href="/docs/zh/datahub/api/reference/introduction#错误" target="_blank" rel="noopener noreferrer">错误</a>。

## 客户端库

Python 与 JavaScript SDK 暂未封装此端点，请直接调用 REST。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.