# Create Catalog

Create a catalog in the current workspace.

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

## Preparation before calling

Prepare a personal access token and target workspace ID that has access to the target workspace.

The example below uses:

- `$AI_STUDIO_API_KEY`: The actual personal access token, passed through the `X-API-Key` Header.
- `$WORKSPACE_ID`: Target workspace ID, passed through `X-Workspace-ID` Header.

## Request example

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/catalog/create" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "<CATALOG_NAME>",
    "description": "<CATALOG_DESCRIPTION>"
  }'
```

## Request body

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | Catalog name, must be a valid identifier. |
| `description` | string | No | Catalog description. |

## Successful response

Returns `200` on success. Save `data.id` for subsequent operations.

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "id": 1
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data.id` | integer or null | ID of the new Catalog; if not provided by the server, it is `null`. |

## Error response

```json
{
  "code": "ErrAlreadyExists",
  "msg": "Catalog 名称已存在",
  "data": null
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 22 32 34

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - `ErrParamInvalid`
  - The request body is invalid, has an empty name, or is not a valid identifier.
  - Use a valid and non-empty `name`.
* - `403`
  - `ErrForbidden`
  - The current identity does not have permission to create Catalog.
  - Requesting permission to `catalog.create`.
* - `409`
  - `ErrAlreadyExists`
  - There is already a Catalog with the same name in the current workspace.
  - Change the name or query the existing catalog.
* - `500`
  - `ErrServer`
  - The server failed to create the Catalog.
  - Try again later.
```

## Follow-up operations

Use `data.id` [Query Catalog details](get-catalog.md).
