Content types

The content model consists of one or more content types, with each type defining key aspects of associated content items, such as available tours.

The properties available for content types are determined by the data model. You can use query attributes to control the set of items returned. Before you start working with content types, you must authenticate.

Note

The base URL used for creating and editing content types is https://content-api.sitecorecloud.io/. For guidance on API syntax, see Syntax.

Get all content types

Use this method to retrieve a list of content types. If you don't specify any filtering parameters, you will retrieve all available content types.

RequestResponse

curl --location '<BASE_URL>/api/content/v1/types' \
--header 'Authorization: <BEARER_TOKEN>'

Get a content type using the ID

You can retrieve a content type using its ID. For a list of content type IDs, run the GET api/content/v1/types method or open the content type details page. This request returns the content type with the ID hotels.

RequestResponse

curl --location --request GET '<BASE_URL>/api/content/v1/types/hotels' \
--header 'Accept: text/plain' \
--header 'Authorization: <BEARER_TOKEN>'
RequestResponse

{
    "id": "hotels",
    "name": {
        "en-US": "Hotels"
    },
    "id": "hotels",
    "description": {
        "en-US": ""
    },
    "fields": [
        {
            "id": "industry",
            "name": {
                "en-US": "Industry"
            },
            "type": "ShortText",
            "required": false,
            "helpText": {
                "en-US": ""
            },
            "reference": null,
            "rules": {}
        },
        {
            "id": "heroImage",
            "name": {
                "en-US": "Hero image"
            },
            "type": "Media",
            "required": false,
            "helpText": {
                "en-US": ""
            },
            "reference": null,
            "rules": {}
        },
        {
            "id": "description",
            "name": {
                "en-US": "Description"
            },
            "type": "LongText",
            "required": false,
            "helpText": {
                "en-US": ""
            },
            "reference": null,
            "rules": {}
        },
        {
            "id": "relatedItems",
            "name": {
                "en-US": "Related items"
            },
            "type": "Reference",
            "required": false,
            "helpText": {
                "en-US": ""
            },
            "reference": null,
            "rules": {}
        }
    ],
    "system": {
        "type": "ContentType",
        "version": "1",
        "status": null,
        "createdBy": {
            "type": "Link",
            "relatedType": "User",
            "id": "[email protected]",
            "uri": "<BASE_URL>/api/content/v1/users/[email protected]"
        },
        "createdAt": "2023-10-12T12:51:04.1187972Z",
        "updatedBy": {
            "type": "Link",
            "relatedType": "User",
            "id": "[email protected]",
            "uri": "<BASE_URL>/api/content/v1/users/[email protected]"
        },
        "updatedAt": "2023-10-12T12:51:04.4326415Z",
        "publishedBy": null,
        "publishedAt": null
    }
}

Search for a content type

You can search for content types using a keyword, and extend the search query using operators. This is similar to searching for content items. The query examines the name, description, and help text fields and is case-insensitive. This request returns the content type where the keyword destinations is found.

RequestResponse

curl --location --request GET '<BASE_URL>/api/content/v1/types?search=destinations' \
--header 'Accept: text/plain' \
--header 'Authorization: <BEARER_TOKEN>'

RequestResponse

{
    "totalCount": 1,
    "pageSize": 20,
    "pageNumber": 1,
    "data": [
        {
            "id": "destination",
            "name": {
                "en-US": "Destination"
            },
            "description": {
                "en-US": "Holds the information about destinations"
            },
            "fields": [
                {
                    "id": "industry",
                    "name": {
                        "en-US": "Industry"
                    },
                    "type": "ShortText",
                    "required": false,
                    "helpText": {
                        "en-US": ""
                    },
                    "reference": null,
                    "rules": {}
                },
                {
                    "id": "heroImage",
                    "name": {
                        "en-US": "Hero image"
                    },
                    "type": "Media",
                    "required": false,
                    "helpText": {
                        "en-US": ""
                    },
                    "reference": null,
                    "rules": {}
                },
                {
                    "id": "shortDescription",
                    "name": {
                        "en-US": "Short description"
                    },
                    "type": "LongText",
                    "required": false,
                    "helpText": {
                        "en-US": ""
                    },
                    "reference": null,
                    "rules": {}
                },
                {
                    "id": "description",
                    "name": {
                        "en-US": "Description"
                    },
                    "type": "RichText",
                    "required": false,
                    "helpText": {
                        "en-US": ""
                    },
                    "reference": null
                },
                {
                    "id": "relatedItemsTitle",
                    "name": {
                        "en-US": "Related Items Title"
                    },
                    "type": "ShortText",
                    "required": false,
                    "helpText": {
                        "en-US": ""
                    },
                    "reference": null,
                    "rules": {}
                },
                {
                    "id": "relatedItemsDescription",
                    "name": {
                        "en-US": "Related Items Description"
                    },
                    "type": "RichText",
                    "required": false,
                    "helpText": {
                        "en-US": ""
                    },
                    "reference": null
                },
                {
                    "id": "relatedItems",
                    "name": {
                        "en-US": "Related items"
                    },
                    "type": "Reference",
                    "required": false,
                    "helpText": {
                        "en-US": ""
                    },
                    "reference": null,
                    "rules": {}
                }
            ],
            "system": {
                "type": "ContentType",
                "version": "EWdpiWWI7BK2NaDwDD5uTvaFMsjrlI39efmzmB2v1UA=",
                "status": null,
                "createdBy": {
                    "type": "Link",
                    "relatedType": "User",
                    "id": "",
                    "uri": "<BASE_URL>/api/content/v1/users/"
                },
                "createdAt": "2024-01-11T21:02:13.8309779Z",
                "updatedBy": {
                    "type": "Link",
                    "relatedType": "User",
                    "id": "[email protected]",
                    "uri": "<BASE_URL>/api/content/v1/users/[email protected]"
                },
                "updatedAt": "2024-02-22T18:24:28.0616408Z",
                "publishedBy": null,
                "publishedAt": null
            }
        }
    ]
}

Create a content type

Use this method to create a content type. The following information is mandatory when you create a content type:

  • Field type - the type of field. Defaults to ShortText if not provided.

  • Name - the name of the content type field.

  • ID - the ID of the content type field.

In the following example, a content type called Tour events is created that has six fields and includes the following validation rules:

  • Limit character count - in this example, the short description must be at least 150 characters but no more than 350 characters. You can add character count validation to ShortText and LongText fields. When you create rules to limit the number of characters, you can specify a minimum value, a maximum value, or both. If validation fails due to an invalid number of characters, the content item can be saved but not published. Rules that limit the number of characters have the following structure:

    RequestResponse
    
    "rules": {
      "length": {
        "min": 150,
        "max": 350
     }
    }
    
  • Limit number of items - in this example, the number of related media items must be no more than four. When you create rules to limit the number of media items, you can specify a minimum value, a maximum value, or both. Rules that limit the number of media items have the following structure:

    RequestResponse
    
    "rules": {
      "limit": {
        "max": 4
     }
    }
    
  • Limit allowed content types - in this example, only content items of type hotels or destinations can be added. Rules that limit the content types have the following structure:

    RequestResponse
    
    "rules": {
      "referencetypes": {
        "values": [
          "hotels",
          "destinations"
        ]
      }
    }
    
RequestResponse

curl --location '<BASE_URL>/api/content/v1/types' \
--header 'Content-Type: application/json' \
--header 'Authorization: <BEARER_TOKEN>' \
--data '{
  "id": "tourEvents",
  "name": {
    "en-US": "Tour events"
  },
  "description": {
    "en-US": "Tour page with events"
  },
  "fields": [
    {
      "id": "industry",
      "name": {
        "en-US": "Industry"
      },
      "type": "ShortText",
      "required": false,
      "helpText": {
        "en-US": ""
      },
      "reference": null,
      "rules": {}
    },
    {
      "id": "tourImages",
      "name": {
        "en-US": "Tour images"
      },
      "type": "Media",
      "required": false,
      "helpText": {
        "en-US": "Related media"
      },
      "reference": null,
      "rules": {
        "limit": {
          "max": 4
        }
      }
    },
    {
      "id": "relatedDestinations",
      "name": {
        "en-US": "Related destinations and hotels"
      },
      "type": "Reference",
      "required": false,
      "helpText": {
        "en-US": ""
      },
      "reference": null,
      "rules": {
        "limit": {
          "min": 2,
          "max": 3
        },
        "referencetypes": {
          "values": [
            "hotels",
            "destinations"
          ]
        }
      }
    },
    {
      "id": "shortDescription",
      "name": {
        "en-US": "Short description"
      },
      "type": "LongText",
      "required": false,
      "helpText": {
        "en-US": ""
      },
      "reference": null,
      "rules": {
        "length": {
          "min": 150,
          "max": 350
        }
      }
    },
    {
      "id": "details",
      "name": {
        "en-US": "Details"
      },
      "type": "RichText",
      "required": false,
      "helpText": {
        "en-US": ""
      },
      "reference": null
    },
    {
      "id": "hotels",
      "name": {
        "en-US": "Hotels"
      },
      "type": "Reference",
      "required": false,
      "helpText": {
        "en-US": ""
      },
      "reference": null,
      "rules": {}
    }
  ]
  }
'

Update a content type

Use this method to update a content type. The following parameters are mandatory when you update a content type:

  • Field type - the type of field. Defaults to ShortText if not provided.

  • Name- the name of the content type field.

  • ID - the ID of the content type field.

This request updates the Tour events content type by adding validation rules that ensure that each tour event references between one and five tour images, and either two or three related destinations. If validation fails due to an invalid number of related destinations, the content item can be saved but not published.

The structure for rules that limit the number of items is:

RequestResponse

"rules": {
 "limit": {
  "min": 2,
  "max": 3
 }
}

You can include only a minimum value, only a maximum value, or both.

RequestResponse

curl --location --request PUT '<BASE_URL>/api/content/v1/types/tourEvents' \
--header 'Content-Type: application/json' \
--header 'Authorization: <BEARER_TOKEN>' \
--data-raw '{
 "name": {
  "en-US": "Tour events"
 },
 "id": "tourEvents",
 "description": {
  "en-US": "Tour page with events"
 },
 "fields": [
  {
   "id": "tourImages",
   "name": {
    "en-US": "Tour images"
   },
   "type": "Media",
   "required": false,
   "helpText": {
    "en-US": ""
   },
   "reference": null,
   "rules": {
     "limit": {
     "min": 1,
     "max": 5,
    }
  }
  },
  {
   "id": "relatedDestinations",
   "name": {
    "en-US": "Related destinations and hotels"
   },
   "type": "Reference",
   "required": false,
   "helpText": {
    "en-US": ""
   },
   "reference": null,
   "rules": {
     "limit": {
      "min": 2,
      "max": 3,
   }
   }
  },
  {
   "id": "shortDescription",
   "name": {
    "en-US": "Short description"
   },
   "type": "LongText",
   "required": false,
   "helpText": {
    "en-US": ""
   },
   "reference": null,
   "rules": []
  },
  {
   "id": "details",
   "name": {
    "en-US": "Details"
   },
   "type": "RichText",
   "required": false,
   "helpText": {
    "en-US": ""
   },
   "reference": null,
   "rules": {}
   }
  ]
 ]
}

Delete a content type

Use this method to delete a content type that is no longer needed. This request deletes a content type with the ID book.

RequestResponse

curl --location --request DELETE '<BASE_URL>/api/content/v1/types/book' \
--header 'Authorization: <BEARER_TOKEN>

Do you have some feedback for us?

If you have suggestions for improving this article,