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

This documentation is a static copy for this version. For current documentation, see: http://dotcms.com/docs/latest

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. The following CRUD operations can be performed, via REST API, on the Content Type object:

Get a Content Type

GET /v1/contenttype/id/{typeId}

The following example 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/v1/contenttype/id/4c441ada-944a-43af-a653-9bb4f3f0cb2b

Create a Content Type

POST /v1/contenttype (JSON object also needs to be defined - see special note below)

The following 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/v1/contenttype -H "Content-Type: application/json" --data @bodyCreate.json

Special Note:

The command above refers 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 ANY Base Type, please see the Create Content Types of each Base Type documentation.

Update a Content Type

`PUT /v1/contenttype/id/{typeId}` (JSON object also needs to be defined - see special note below)

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/v1/contenttype/id/39fecdb0-46cc-40a9-a056-f2e1a80ea78c -H "Content-Type: application/json" --data @bodyUpdate.json

Special Note:

The command above passes a file called bodyUpdate.json which contains the following 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

DELETE /v1/contenttype/id/{typeId}

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

Example:

curl -v -u admin@dotcms.com:admin -XDELETE http://localhost:8080/api/v1/contenttype/id/05c64f1d-2d39-4b93-95c4-99d72ebe869a