# Update SQL draft version

Modifying the SQL content saved in the draft version will not execute the SQL. The finalized version cannot be modified.

```text
POST https://moi.matrixorigin.cn/newmoi/workbook/version/update
```

## Preparation before calling

Prepare your personal access token, workspace ID, SQL save record ID, and draft version ID with update permissions. `$AI_STUDIO_API_KEY` is the personal access token used as the value of the `X-API-Key` request header; `$WORKSPACE_ID` is the target workspace ID used as the value of the `X-Workspace-ID` request header. You can first [View saved SQL version](list-workbook-versions.md) to 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`.

## Request body

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

::::{div} mo-api-split
:::{div} mo-api-split-main
```{raw} html
<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 of the SQL save record with status `draft`.</dd></div>
<div class="mo-api-field"><dt><code>sql_content</code><span class="mo-api-field__type">string</span></dt><dd>The SQL content to be saved.</dd></div>
</dl>
```
:::
:::{div} mo-api-split-aside
```{raw} html
<p class="mo-api-example-label">Request example</p>
```
```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/workbook/version/update" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d "{
    \"workbook_id\": \"$WORKBOOK_ID\",
    \"version_id\": \"$VERSION_ID\",
    \"sql_content\": \"SELECT 1\"
  }"
```
:::
::::
## Successful response

`data` is empty on success. You can then [View the saved SQL version content](get-workbook.md) to confirm the saved SQL content.

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

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `data` | null | Fixed to `null` when the update is successful. |

## Error response

::::{div} mo-api-split
:::{div} mo-api-split-main
```{raw} html
<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
```{raw} html
<p class="mo-api-example-label">Error response example</p>
```
```json
{
  "code": 404,
  "message": "SQL 工作簿或版本不存在"
}
```
:::
::::
## Follow-up operations

Use the same resource identifier [View saved SQL version content](get-workbook.md) to confirm the update result.
