# Create SQL workbook

Create a SQL workbook that holds SQL content and its versions. After success, save the returned `workbook_id` for creating and managing versions.

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

## Preparation before calling

Prepare a personal access token and target workspace ID with permission to create SQL save records. `$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.

`$WORKBOOK_NAME` in the example below is the name of the saved record.

## 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>name</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The name of the saved record.</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/create" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d "{
    \"name\": \"$WORKBOOK_NAME\"
  }"
```
:::
::::
## Successful response

`data.workbook_id` is the ID of the newly saved record, and `data.name` is the record name. After saving `workbook_id`, first [View SQL saved record version](list-workbook-versions.md) to obtain the version ID; when you need to add an editable version, then [Create SQL draft version](create-workbook-draft.md).

```json
{
  "code": 200,
  "data": {
    "workbook_id": "workbook-123",
    "name": "销售分析"
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | `200` on success. |
| `data.workbook_id` | string | Create a new SQL ID to save the record. |
| `data.name` | string | The name of the saved record. |

## 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": 400,
  "message": "请求参数无效"
}
```
:::
::::
## Follow-up operations

Logging `data.workbook_id`. First [View the version of the SQL saved record](list-workbook-versions.md) to obtain `version_id`, and then use the two IDs to [View the version content of the saved SQL](get-workbook.md).
