Content Type API - Documentation topics on: content type api,content types,rest api,.

Content Type API

You can use the dotCMS REST API to manage Content Types. Content Types can be created, updated, and deleted via REST API. In addition, Content Type Fields and Content Type Field Variables can also be managed via REST API.

Get a Content Type

Usage:

GET /v1/contenttype/id/{typeId}

Example:

The following curl command retrieves a specific field by ID, and returns all the properties of the field:

curl -v -u admin@dotcms.com:admin -XGET http://localhost:8080/api<font color="Crimson">/v1/contenttype/</font><font color="Green">id/4c441ada-944a-43af-a653-9bb4f3f0cb2b</font>

Create a Content Type

Usage:

POST /v1/contenttype

Note: The JSON object also needs to be defined - please see below.

Example:

The following curl command creates a new Content Type, using the bodyCreate.json file, which includes all the properties required to create the new Content Type:

curl -v -u admin@dotcms.com:admin -XPOST http://localhost:8080/api/<font color="Crimson">v1</font><font color="Green">/contenttype -H "Content-Type: application/json" --data @bodyCreate.json</font>
Payload

The command above passes a file called bodyCreate.json which contains the following new Content Type properties in order to create the specified Content Type. The contents of the bodyCreate.json file are shown below:

{
  "clazz": "com.dotcms.contenttype.model.type.ImmutableSimpleContentType", 
  "defaultType": false, 

  "name": "The Content Type 1", 
  "description": "THE DESCRIPTION", 

  "host": "48190c8c-42c4-46af-8d1a-0cd5db894797", 
  "owner": "dotcms.org.1", 

  "variable": "TheContentType1",

  "fixed": false, 
  "system": false, 
  "folder": "SYSTEM_FOLDER"
}

The json object properties of any new Content Type can be seen by examining the json view link when editing a Content Type.

Creating Content Types of Different Base Types: For examples of how to create a Content Type of other Base Content Types, please see the Create Content Types of each Base Type documentation.

Update a Content Type

Usage:

PUT /v1/contenttype/id/{typeId}

Note: The JSON object also needs to be defined - please see below.


Important

When updating a Content Type using the REST API, you must submit all fields for a Content Type each time you update it.

  • If you wish to update only a single field (while maintaining all other existing fields), you must first read all existing fields so you can include them when updating the Content Type.
  • Any fields which are not included when you update a Content Type via the REST API will be removed from that Content Type.

Example:

The following command updates an existing Content Type (by ID), using the bodyUpdate.json file to define the json object required to update the Content Type's properties.

curl -v -u admin@dotcms.com:admin -XPUT http://localhost:8080/api<font color="Crimson">/v1</font><font color="Green">/contenttype/id/39fecdb0-46cc-40a9-a056-f2e1a80ea78c -H "Content-Type: application/json" --data @bodyUpdate.json</font>

Payload

The command above passes a file called bodyUpdate.json which contains the new Content Type properties that will be used to Update the specified Content Type. The contents of the bodyUpdate.json file are shown below:

{
    "clazz": "com.dotcms.contenttype.model.type.ImmutableSimpleContentType", 
    "defaultType": false,
    "id": "39fecdb0-46cc-40a9-a056-f2e1a80ea78c",

    "name": "The Content Type 2",
    "description": "THE DESCRIPTION 2",

    "host": "48190c8c-42c4-46af-8d1a-0cd5db894797",
    "owner": "dotcms.org.1",

    "variable": "TheContentType1",

    "fixed": false,
    "system": false,
    "folder": "SYSTEM_FOLDER"
}

The json object properties of any Content Type can be seen by examining the json view link when editing a Content Type.

Delete a Content Type

Usage:

DELETE /v1/contenttype/id/{typeId}

Example:

The following command deletes the field specified by identifier, from the specified Content Type (by identifier):

curl -v -u admin@dotcms.com:admin -XDELETE http://localhost:8080/api<font color="Crimson">/v1/contenttype/</font><font color="Green">id/05c64f1d-2d39-4b93-95c4-99d72ebe869a</font>