# View SQL workbook version list

List all versions of a SQL workbook. Use the returned `version_id` to view the content, update a draft, or finalize the version.

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

## Preparation before calling

Prepare the personal access token, workspace ID, and SQL save record ID. `$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_ID` in the example below is the SQL save record ID of the version you want to view. At most `100` versions are returned at a time; `20` are returned when `page_size` is not specified. When the `next_page_token` in the response is not empty, fill the value into the `page_token` of the next request as it is; when it is empty, it means that the last page has been reached.

## 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>page_size</code><span class="mo-api-field__type">integer</span></dt><dd>Number per page, ranging from `1` to `100`; if not passed, it is `20`.</dd></div>
<div class="mo-api-field"><dt><code>page_token</code><span class="mo-api-field__type">string</span></dt><dd>Next page token.</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/list" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d "{
    \"workbook_id\": \"$WORKBOOK_ID\"
  }"
```
:::
::::
## Successful response


`data.result` is the version list. `status` means `draft` means editable draft, `finalize` means finalized and read-only.

```json
{
  "code": 200,
  "data": {
    "total": 1,
    "result": [
      {
        "id": "version-123",
        "name": "v1",
        "status": "draft"
      }
    ],
    "next_page_token": ""
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `data.total` | integer | The total number of versions of the current SQL saved records. |
| `data.result` | array | Version list. |
| `data.result[].id` | string | Version ID. |
| `data.result[].name` | string | Version name. |
| `data.result[].status` | string | Version status: `draft` means editable draft; `finalize` means finalized, read-only. |
| `data.next_page_token` | string | Next page mark; if empty, there will be no next page. |

In this document, `[]` after a type denotes an array. In a field path, `[]` denotes each item in an array; for example, `data.result[].id` is the `id` field of each item in the `data.result` array.


## 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

Save the identifier of the target item, and then [View SQL workbook version content](get-workbook.md).
