# Finalize SQL version

Save and finalize a draft version. After finalization this version is read-only and the SQL text cannot be updated.

```text
POST $CLOUDSIGMA_API_BASE/workbook/version/save
```

## Before you call this API

Configure the [regional API endpoint and authentication](https://omnifabric.cloudsigma.com/docs/developer/endpoints-and-authentication.html.md), and select the target workspace.

First [list saved SQL versions](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/data-processing/sql-workbooks/list-workbook-versions.html.md) and confirm the version status.

`$WORKBOOK_ID` in the example below is the ID of the SQL saved record and `$VERSION_ID` is the version ID with status `draft`. If you need to modify the finalized SQL, create a new draft version.

## Request body

Replace caller-specific values in the example with actual values.

::::{div} mo-api-split
:::{div} mo-api-split-main
<dl class="mo-api-fields">
<div class="mo-api-field"><dt><code>workbook_id</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The ID of the SQL saved record.</dd></div>
<div class="mo-api-field"><dt><code>version_id</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The version ID in the SQL save record to be finalized.</dd></div>
<div class="mo-api-field"><dt><code>sql_content</code><span class="mo-api-field__type">string</span></dt><dd>SQL content saved together when finalizing.</dd></div>
</dl>
:::
:::{div} mo-api-split-aside
<p class="mo-api-example-label">Request example</p>
```bash
curl -X POST "$CLOUDSIGMA_API_BASE/workbook/version/save" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d "{
    \"workbook_id\": \"$WORKBOOK_ID\",
    \"version_id\": \"$VERSION_ID\"
  }"
```
:::
::::
## Successful response

`data` is empty on success. You can then [View the version of the saved SQL](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/data-processing/sql-workbooks/list-workbook-versions.html.md) to confirm that this version of `status` is `finalize`.

```json
{
  "code": 200,
  "data": null
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `data` | null | Fixed to `null` when finalized successfully. |

## Error response

::::{div} mo-api-split
:::{div} mo-api-split-main
<dl class="mo-api-fields">
<div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">integer or string</span></dt><dd>Error code or status.</dd></div>
<div class="mo-api-field"><dt><code>message</code><span class="mo-api-field__type">string</span></dt><dd>Error message.</dd></div>
</dl>
:::
:::{div} mo-api-split-aside
<p class="mo-api-example-label">Error response example</p>
```json
{
  "code": 400,
  "message": "请求参数无效"
}
```
:::
::::
## Follow-up operations

After completion [View saved SQL version content](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/data-processing/sql-workbooks/get-workbook.html.md) confirms the current status.
