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 with content types. 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 a full list of fields, parameters, and technical limitations, see the data model. For guidance on API syntax, see Syntax.

Get all content types

Use this method to retrieve a list of all the content types currently defined.

RequestResponsehttp
GET {Base URL}/api/content/v1/types

Request

RequestResponsehttp
GET {Base URL}/api/content/v1/types?pageNumber=3&pageSize=10

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.

RequestResponsehttp
GET {Base URL}/api/content/v1/types/{contentTypeId}

Request

This code sample returns the content type Hotels.

RequestResponsehttp
GET {Base URL}/api/content/v1/types/hotels

Response

RequestResponseshell
{
    "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": "david.d@sitecore.com",
            "uri": "http://content-api.sitecorecloud.io/api/content/v1/users/david.d@sitecore.com"
        },
        "createdAt": "2023-10-12T12:51:04.1187972Z",
        "updatedBy": {
            "type": "Link",
            "relatedType": "User",
            "id": "david.d@sitecore.com",
            "uri": "http://content-api.sitecorecloud.io/api/content/v1/users/david.d@sitecore.com"
        },
        "updatedAt": "2023-10-12T12:51:04.4326415Z",
        "publishedBy": null,
        "publishedAt": null
    }
}

Create a content type

Use this method to create a content type. The following are 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.
RequestResponsehttp
POST {Base URL}/api/content/v1/types

Request

This sample creates a content type called Tour events that has six fields and includes validation rules for a ShortText field. You can add rules to ShortText and LongText fields to limit the character count. In this example, the short description must be at least 150 characters but no more than 350 characters. If validation fails due to an invalid number of characters, the content item can be saved but not published.

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

RequestResponseshell
"rules": {
  "length": {
    "min": 150,
    "max": 350
  }
}

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

RequestResponseshell
{
  "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": ""
      },
      "reference": null,
      "rules": {}
    },
    {
      "id": "relatedDestinations",
      "name": {
        "en-US": "Related destinations and hotels"
      },
      "type": "Reference",
      "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": {
        "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": {}
    }
  ],
  "system": {
    "type": "ContentType",
    "version": "1",
    "status": null,
    "createdBy": {
      "type": "Link",
      "relatedType": "User",
      "id": "david.d@sitecore.com",
      "uri": "http://content-api.sitecorecloud.io/api/content/v1/users/david.d@sitecore.com"
    },
    "createdAt": "2023-10-12T13:34:27.6582449Z",
    "updatedBy": {
      "type": "Link",
      "relatedType": "User",
      "id": "david.d@sitecore.com",
      "uri": "http://content-api.sitecorecloud.io/api/content/v1/users/david.d@sitecore.com"
    },
    "updatedAt": "2023-10-12T13:40:11.8502648Z",
    "publishedBy": null,
    "publishedAt": null
  }
}

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.
RequestResponsehttp
PUT {Base URL}/api/content/v1/types/{contentTypeId}

Request

This code sample 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:

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

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

RequestResponseshell
{
  "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": {}
    }
  ],
  "system": {
    "type": "ContentType",
    "version": "1",
    "status": null,
    "createdBy": {
      "type": "Link",
      "relatedType": "User",
      "id": "thomas.louis@sitecore.com",
      "uri": "http://content-api.sitecore.cloud.io/api/content/v1/users/thomas.louis@sitecore.com"
    },
    "createdAt": "2023-06-12T21:19:00.7609622Z",
    "updatedBy": {
      "type": "Link",
      "relatedType": "User",
      "id": "thomas.louis@sitecore.com",
      "uri": "http://content-api.sitecore.cloud.io/api/content/v1/users/thomas.louis@sitecore.com"
    },
    "updatedAt": "2023-08-29T18:41:57.1150208Z",
    "publishedBy": null,
    "publishedAt": null
  }
}

Delete a content type

Use this method to delete a content type that is no longer needed.

RequestResponsehttp
DELETE {Base URL}/api/content/v1/types/{contentTypeId}

Request

This code sample deletes a content type with the ID customerReviews.

RequestResponsehttp
DELETE {Base URL}/api/content/v1/types/customerReviews

Do you have some feedback for us?

If you have suggestions for improving this article,