# Create SQL draft version

Creates an editable draft version of a SQL save record and saves the original SQL content.

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

## Preparation before calling

Prepare your personal access token, workspace ID, and SQL save record 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 [Create SQL Save Record](create-workbook.md) to obtain `workbook_id`.

`$WORKBOOK_ID` in the example below is the ID of the SQL saved record. `sql_content` only saves the SQL content and does not execute the SQL.

## 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>sql_content</code><span class="mo-api-field__type">string</span></dt><dd>Draft SQL content.</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/create" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d "{
    \"workbook_id\": \"$WORKBOOK_ID\",
    \"sql_content\": \"SELECT 1\"
  }"
```
:::
::::
## Successful response

`data.id` is the new draft version ID. After saving the ID, you can [update draft version](update-workbook-draft.md) or [final version](finalize-workbook-version.md).

```json
{
  "code": 200,
  "data": {
    "id": "version-123",
    "version": "v1",
    "status": "draft"
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `data.id` | string | New draft version ID. |
| `data.version` | string | Version name. |
| `data.status` | string | New version status, which is `draft`. |

## 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": 500,
  "message": "Internal server error"
}
```
:::
::::
## Follow-up operations

Log `data.id`. Use this ID [View saved SQL version content](get-workbook.md) to confirm the save result.
