Fields - Content Type API

Last Updated: Jan 27, 2020
documentation for the dotCMS Content Management System

You can use the dotCMS REST API to manage fields on Content Types, performing many of the same operations that are documented in the Content Type Fields documentation.

In the curl examples below, admin passwords are assumed to be admin, as on the demo site and starters prior to version 22.06. For versions 22.06 or later, this is no longer the default; now, admin passwords default to a random string generated on first startup and displayed in the server logs. This starter password can also be pre-configured through the DOT_INITIAL_ADMIN_PASSWORD environment variable.

List All Fields

GET /v1/contenttype/{typeId}/fields

List all fields of given content type (must supply the content type id and the field id):

curl -v -u admin@dotcms.com:admin -XGET http://localhost:8082/api/v1/contenttype/ddf29c1e-babd-40a8-bfed-920fc9b8c77f/fields

Note: To see the properties of a Content Type and Content Type fields, see the JSON View - Content Types documentation.

Get a Field by ID

GET /v1/contenttype/{typeId}/fields/id/{fieldID}

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:8082/api/v1/contenttype/ddf29c1e-babd-40a8-bfed-920fc9b8c77f/fields/id/baf97686-348e-480e-9fc5-3216339b35b8

Get Field by Variable

GET /v1/contenttype/{typeId}/fields/var/{fieldVar}

The following example retrieves a specific field by Variable, and returns all the properties of the field:

curl -v -u admin@dotcms.com:admin -XGET http://localhost:8082/api/v1/contenttype/ddf29c1e-babd-40a8-bfed-920fc9b8c77f/fields/var/firstName

Create Field

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

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

curl -v -u admin@dotcms.com:admin -XPOST http://localhost:8082/api/v1/contenttype/ddf29c1e-babd-40a8-bfed-920fc9b8c77f/fields -H "Content-Type: application/json" --data @bodyCreate.json

Special Note:

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

  
{
    "clazz" : "com.dotcms.contenttype.model.field.ImmutableTextField",
    "contentTypeId" : "ddf29c1e-babd-40a8-bfed-920fc9b8c77f",
    "dataType" : "TEXT",
    "name" : "The Field 1",

    "defaultValue" : "THE DEFAULT VALUE",
    "regexCheck" : "THE VALIDATION REGEX",
    "hint" : "THE HINT",

    "sortOrder" : 11,
    "readOnly" : "false",
    "fixed" : "false",

    "required" : "true",
    "searchable" : "true",
    "indexed" : "true",
    "listed" : "true",
    "unique" : "false"
}

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

Update Existing Field by ID {#updateExistingFieldByID}

PUT /v1/contenttype/{typeId}/fields/id/{fieldID}

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

curl -v -u admin@dotcms.com:admin -XPUT http://localhost:8082/api/v1/contenttype/ddf29c1e-babd-40a8-bfed-920fc9b8c77f/fields/id/9f31618d-418d-4af8-a554-490ab0d93f5d -H "Content-Type: application/json" --data @bodyUpdate.json

Special Note:

The command above refers passes a file called bodyUpdate.json which contains the following field properties in order to Update a text field on the specified Content Type. The contents of the bodyUpdate.json file are shown below:

  
{
    "clazz" : "com.dotcms.contenttype.model.field.ImmutableTextField",
    "contentTypeId" : "ddf29c1e-babd-40a8-bfed-920fc9b8c77f",
    "dataType" : "TEXT",
    "name" : "The Field 2",

    "id" : "9f31618d-418d-4af8-a554-490ab0d93f5d",
    "sortOrder":"12",
    "variable" : "theField1",

    "defaultValue" : "THE DEFAULT VALUE 2",
    "regexCheck" : "THE VALIDATION REGEX 2",
    "hint" : "THE HINT 2",

    "required" : "false",
    "searchable" : "false",
    "indexed" : "false",
    "listed" : "false",
    "unique" : "false"
}

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

Delete Field by ID

DELETE /v1/contenttype/{typeId}/fields/id/{fieldID}

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:8082/api/v1/contenttype/ddf29c1e-babd-40a8-bfed-920fc9b8c77f/fields/id/9f31618d-418d-4af8-a554-490ab0d93f5d

Delete Field by Variable

DELETE /v1/contenttype/{typeId}/fields/var/{fieldVar}

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

Example:

curl -v -u admin@dotcms.com:admin -XDELETE http://localhost:8082/api/v1/contenttype/ddf29c1e-babd-40a8-bfed-920fc9b8c77f/fields/var/theField1

On this page

×

We Dig Feedback

Selected excerpt:

×