# Update a content type

_NgCms / Content Types_

`PUT /ng-cms/content-types/{projectId}/{key}`

## Parameters

- `projectId` (string, required) — The unique identifier of the project
- `key` (string, required) — The ID or key of the content type to update

## Request Body

### `UpdateContentTypeRequest`

- `id` (string, required) — ID of the content type to update
- `name` (string, required) — Human-readable display name for the content type
- `key` (string, required) — Unique machine-readable identifier for the content type (e.g. 'blog-post')
- `description` (string, optional) — Optional description of the content type's purpose
- `displayField` (string, optional) — Key of the schema field used as the display/title field for entries
- `schema` (CmsSchemaField[], optional) — Full replacement array of field definitions for the content type's schema

### `CmsSchemaField`

- `key` (string, required) — Unique field identifier within the schema
- `label` (string, required) — Human-readable field label
- `type` (string, required) — Field data type: text, richtext, number, boolean, date, reference
- `required` (boolean, optional) — Whether the field is required when creating entries
- `minLength` (number, optional) — Minimum character length for text fields
- `maxLength` (number, optional) — Maximum character length for text fields
- `min` (number, optional) — Minimum value for numeric fields
- `max` (number, optional) — Maximum value for numeric fields
- `regex` (string, optional) — Regular expression pattern for value validation
- `unique` (boolean, optional) — Whether field values must be unique across entries
- `allowedValues` (string[], optional) — Enumerated list of permitted values
- `referenceContentTypeId` (string, optional) — ID of another content type for reference/relation fields

## Responses

### `200` — Content type updated successfully. Returns the content type ID.

Type: `ApiResponse<string>`

- `success` (boolean) — Indicates whether the request was successful
- `result` (string) — The ID of the updated content type
- `errors` (ErrorDetail[]) — List of errors (empty on success)

### `400` — Validation failed — required fields missing or schema is invalid.

Type: `ApiResponse<T>`

- `isValid` (boolean) — Always false for validation errors
- `validationErrors` (ValidationError[]) — List of validation failures
  - `name` (string) — Field that failed validation
  - `attemptedValue` (object) — The value that was submitted
  - `message` (string) — Human-readable validation message

### `401` — Unauthorized. A valid API key is required.


### `404` — Not Found. No content type exists with the given ID or key.


### `412` — Precondition Failed. The project's current plan does not allow access to this resource, or payment is required to proceed.


### `500` — Unexpected server error.

Type: `ApiResponse<T>`

- `success` (boolean) — Always false
- `errors` (ErrorDetail[]) — List of server-side errors
  - `correlationId` (string) — Unique ID for tracing the error
  - `message` (string) — Error message
  - `stack` (string) — Stack trace (non-production only)


## Code Examples

### curl

```curl
curl --request PUT \\
  --url https://apis-spb.konso.io/ng-cms/content-types/{projectId}/{key} \\
  --header 'x-api-key: <api-key>' \\
  --header 'Content-Type: application/json' \\
  --data '{
  "name": "Blog Post",
  "key": "blog-post",
  "description": "Updated blog post content type",
  "displayField": "title",
  "schema": [
    { "key": "title", "label": "Title", "type": "text", "required": true, "maxLength": 300 },
    { "key": "body",  "label": "Body",  "type": "richtext", "required": true }
  ]
}'
```

### javascript

```js
const options = {
  method: 'PUT',
  headers: {
    'x-api-key': '<api-key>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'Blog Post',
    key: 'blog-post',
    description: 'Updated blog post content type',
    displayField: 'title',
    schema: [
      { key: 'title', label: 'Title', type: 'text', required: true, maxLength: 300 },
      { key: 'body', label: 'Body', type: 'richtext', required: true }
    ]
  })
};

fetch('https://apis-spb.konso.io/ng-cms/content-types/{projectId}/{key}', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
```

### dotnet

```dotnet
var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", "<api-key>");

var request = new UpdateContentTypeRequest
{
    Name = "Blog Post",
    Key = "blog-post",
    Description = "Updated blog post content type",
    DisplayField = "title",
    Schema = new List<CmsSchemaField>
    {
        new() { Key = "title", Label = "Title", Type = "text", Required = true, MaxLength = 300 },
        new() { Key = "body",  Label = "Body",  Type = "richtext", Required = true }
    }
};

var response = await client.PutAsJsonAsync("https://apis-spb.konso.io/ng-cms/content-types/{projectId}/{key}", request);
var result = await response.Content.ReadFromJsonAsync<ApiResponse<string>>();
```

### python

```python
import requests

url = "https://apis-spb.konso.io/ng-cms/content-types/{projectId}/{key}"
headers = {
    "x-api-key": "<api-key>",
    "Content-Type": "application/json"
}
payload = {
    "name": "Blog Post",
    "key": "blog-post",
    "description": "Updated blog post content type",
    "displayField": "title",
    "schema": [
        {"key": "title", "label": "Title", "type": "text", "required": True, "maxLength": 300},
        {"key": "body",  "label": "Body",  "type": "richtext", "required": True}
    ]
}

response = requests.put(url, json=payload, headers=headers)
print(response.json())
```

### Request Body Example

```json
{
  "projectId": "example-string",
  "key": "example-string"
}
```

### Response Example (200)

```json
{
  "success": true,
  "result": "ct_a1b2c3d4e5f6",
  "errors": []
}
```

## Repositories

- [konso-cms-nodejs](https://gitverse.ru/konso/konso-cms-nodejs)
- [konso-cms-dotnet](https://gitverse.ru/konso/konso-cms-dotnet)

## Packages

- `dotnet add package Konso.Clients.Cms` — [Konso.Clients.Cms](https://nugetprodusnc-northcentralus-01.regional.azure-api.net/packages/Konso.Clients.Cms)
- `npm install @konso/cms-client` — [@konso/cms-client](https://www.npmjs.com/package/@konso/cms-client)
