You can use the dotCMS REST API to manage field variables on Content Types, performing many of the same operations that are documented in the Content Type Fields documentation.
List All Field Variables of a Specific Field (by ID)
GET /v1/contenttype/{typeId}/fields/id/{fieldId}/variables
List all Field Variables, for a specific field, on a 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/id/0dbb0e2e-679f-420b-94a6-10d114288c0b/variables
List All Field Variables of a Specific Field (by Variable)
GET /v1/contenttype/{typeId}/fields/var/{fieldVar}/variables
The following example retrieves all Field Variables for specific field by VARIABLE, on a given content type (must supply the content type id and the variable 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/variables
Get Field Variable by ID (and field ID)
GET /v1/contenttype/{typeId}/fields/id/{fieldId}/variables/id/{fieldVarId}
The following example retrieves all the properties of a specific Field Variable, after passing the Field Variable ID and the Field ID:
{curl
bodyUpdate.json curl -v -u admin@dotcms.com:admin -XGET http://localhost:8082/api/v1/contenttype/ddf29c1e-babd-40a8-bfed-920fc9b8c77f/fields/id/0dbb0e2e-679f-420b-94a6-10d114288c0b/variables/id/c6948459-ee6b-4f19-8d24-f98e77099325
Get Field Variable by ID (and field Var)
GET /v1/contenttype/{typeId}/fields/var/{fieldVar}/variables/id/{fieldVarId}
The following example retrieves all the properties of a specific Field Variable, after passing the Field Variable 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/var/firstName/variables/id/c6948459-ee6b-4f19-8d24-f98e77099325
Create Field Variable on Content Type and Field (using field ID)
POST /v1/contenttype/{typeId}/fields/id/{fieldId}/variables
(Define JSON object using a file)
The following command creates a Field Variable, using the bodyCreate.json file to define the json object required to create the field's properties. This command requires the Content Type ID, and the Field ID on which the Field Variable is to be added.
curl -v -u admin@dotcms.com:admin -XPOST http://localhost:8082/api/v1/contenttype/ddf29c1e-babd-40a8-bfed-920fc9b8c77f/fields/id/0dbb0e2e-679f-420b-94a6-10d114288c0b/variables -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.ImmutableFieldVariable", "fieldId": "0dbb0e2e-679f-420b-94a6-10d114288c0b", "key": "myFieldVariableKey1", "value": "My Field Variable Value 1" }
The json object properties of any field can be seen by examining the JSON view link when editing a Content Type.
Create Field Variable on Content Type and Field (using field Var)
POST /v1/contenttype/{typeId}/fields/var/{fieldVar}/variables
(Define JSON object using a file)
The following command creates a Field Variable, using the bodyCreate.json file to define the json object required to create the field's properties. This command requires the Content Type ID, and the variable of the field on which the Field Variable is to be added.
curl -v -u admin@dotcms.com:admin -XPOST http://localhost:8082/api/v1/contenttype/ddf29c1e-babd-40a8-bfed-920fc9b8c77f/fields/id/0dbb0e2e-679f-420b-94a6-10d114288c0b/variables -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.ImmutableFieldVariable", "fieldId": "0dbb0e2e-679f-420b-94a6-10d114288c0b", "key": "myFieldVariableKey1", "value": "My Field Variable Value 1" }
The json object properties of any field can be seen by examining the json view link when editing a Content Type.
Update Field Variable on Content Type and Field (using field ID)
PUT /v1/contenttype/{typeId}/fields/id/{fieldId}/variables/id/{fieldVarId}
(Define JSON object using a file)
The following command updates a Field Variable, using the bodyUpdate.json file to define the json object required to update the field's properties. This command requires the Content Type ID, and the Field ID on which the Field Variable is to be updated.
curl -v -u admin@dotcms.com:admin -XPUT http://localhost:8082/api/v1/contenttype/ddf29c1e-babd-40a8-bfed-920fc9b8c77f/fields/id/0dbb0e2e-679f-420b-94a6-10d114288c0b/variables/id/c6948459-ee6b-4f19-8d24-f98e77099325 -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.ImmutableFieldVariable", "fieldId": "0dbb0e2e-679f-420b-94a6-10d114288c0b", "id": "c6948459-ee6b-4f19-8d24-f98e7709932", "key": "myFieldVariableKey2", "value": "My Field Variable Value 2" }
The json object properties of any field can be seen by examining the JSON view link when editing a Content Type.
Update Existing Field Variable on Content Type and Field (using field Var)
PUT /v1/contenttype/{typeId}/fields/var/{fieldVar}/variables/id/{fieldVarId}
(Define JSON object using a file)
The following command updates a Field Variable, using the bodyUpdate.json file to define the json object required to update the field's properties. This command requires the Content Type ID, and the variable of the field on which the Field Variable is to be updated.
curl -v -u admin@dotcms.com:admin -XPUT http://localhost:8082/api/v1/contenttype/ddf29c1e-babd-40a8-bfed-920fc9b8c77f/fields/var/firstName/variables/id/c6948459-ee6b-4f19-8d24-f98e77099325 -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.ImmutableFieldVariable", "fieldId": "0dbb0e2e-679f-420b-94a6-10d114288c0b", "id": "c6948459-ee6b-4f19-8d24-f98e7709932", "key": "myFieldVariableKey2", "value": "My Field Variable Value 2" }
The json object properties of any field can be seen by examining the json view link when editing a Content Type.
Delete Field Variable by Field Variable ID and Field ID
DELETE /v1/contenttype/{typeId}/fields/id/{fieldId}/variables/id/{fieldVarId}
Deletes the Field Variable specified by Field Variable identifier and the Field 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/0dbb0e2e-679f-420b-94a6-10d114288c0b/variables/id/c6948459-ee6b-4f19-8d24-f98e77099325
Delete Field Variable ID and by Field Var
DELETE /v1/contenttype/{typeId}/fields/var/{fieldVar}/variables/id/{fieldVarId}
Deletes the Field Variable specified by Field Variable identifier and the Field 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/firstName/variables/id/de7d7b1b-4f44-46fc-ae1f-61feccada434