Content Type

最后更新:2026年7月3日

CDA(Content Delivery API)是将已发布资源传递给公开访问者的只读 API。本页介绍如何查询已发布的 Content Type,即 Content 所遵循的框架(schema)。通过 CDA 读取该框架包含哪些字段,以及每个字段的类型、是否多语言、是否必填、校验规则,就能预先了解遵循该框架的已发布 Content 的形态。

CDA 仅提供查询(GET)端点,创建、修改和发布 Content Type 的操作由 CMA Content Type 负责。关于认证和发布传递模型(发布快照、revision、仅显示已发布内容)等 CDA 通用行为,请参阅 CDA 概述。由于 Content Type 是框架的 schema,查询时不接受 locale 参数。

资源结构

下面是 CDA 通过单条查询传递的演示 Space 中已发布 Content Type "商品" 的形态。它除了 sys(系统属性)之外,还包含 namedisplayFieldpublishWithAuthorfields 等正文属性。

{
  "sys": {
    "id": "3trmXRLdJF4GBlAjtcuoZ7Pnxj8dlA",
    "type": "ContentType",
    "space": { "sys": { "id": "HnQ32YiH", "type": "Refer", "targetType": "Space" } },
    "createdAt": "2026-06-14T17:04:46.846Z",
    "updatedAt": "2026-06-17T03:13:49.943Z",
    "revision": 7
  },
  "name": "商品",
  "displayField": "productName",
  "fields": [
    { "id": "5n06s7ocmwdi", "name": "商品名称", "apiName": "productName", "type": "ShortText", "localized": true, "required": true, "validations": [], "disabled": false },
    { "id": "1gecyz8g4llwf", "name": "价格", "apiName": "price", "type": "Long", "localized": false, "required": false, "validations": [], "disabled": false },
    { "id": "3ow4popgz54zg", "name": "详细说明", "apiName": "description", "type": "RichText", "localized": true, "required": false, "validations": [], "disabled": false },
    { "id": "2alxdptmdub1s", "name": "主图", "apiName": "photo", "type": "Refer", "localized": false, "required": false, "validations": [], "disabled": false, "targetType": "Media" },
    {
      "id": "2a80lehazfx3t",
      "name": "品牌",
      "apiName": "brand",
      "type": "Refer",
      "localized": false,
      "required": false,
      "validations": [
        { "referContentType": [ { "sys": { "id": "3trmXRM3RqbgSnifyg7OveRYWnJWEG", "type": "Refer", "targetType": "ContentType" } } ] }
      ],
      "disabled": false,
      "targetType": "Content"
    }
  ],
  "publishWithAuthor": false
}

主要键:

  • sys.idContent Type 的唯一标识符。用于填入单条查询路径中的 {contentTypeId}
  • sys.revision:公开时刻的版本。CDA 不携带管理用的 version,因此指向发布版本的值只有 revision 一个。
  • nameContent Type 的名称(例如 商品)。
  • displayField:在内容工作室列表中代表每条 Content 显示的字段的 apiName(例如 productName)。
  • publishWithAuthor:发布 Content 时是否一并携带作者信息(示例为 false)。
  • fields:该框架定义的字段列表。各项的结构在下方 字段 中说明。

系统属性 (sys)

已发布 Content Typesys 仅携带发布快照用的属性。spacecreatedByupdatedByRefer 形态({ "sys": { "id", "type": "Refer", "targetType" } })出现。

属性类型说明
idstring资源唯一标识符。
typestring资源种类。Content Type 始终为 "ContentType"
spaceRefer<Space>Content Type 所属的 Space
createdAtstring (date-time)创建时间。
updatedAtstring (date-time)最后修改时间。
revisioninteger公开时刻的版本。每次发布时该时刻的版本都会写入此处。
createdByRefer<User>创建该资源的用户。仅当 Content TypepublishWithAuthor 开启时才包含。
updatedByRefer<User>最后修改的用户。仅当 publishWithAuthor 开启时才包含。

由于是发布快照,CMA 的 sys 中的 versionstatuspublisharchive 都不会携带。指向发布版本的值只有 revision 一个。

字段

fields 是该 Content Type 定义的字段列表。每一项具有以下结构(FieldDefinition)。

类型说明
idstring字段的唯一标识符。
namestring内容工作室中显示的字段名称(例如 商品名称)。
apiNamestringAPI 中指向该字段的键。在已发布 Contentfields 中也用此键读取值。
typestring (enum)字段的类型。参见下方 字段种类 (type)
localizedboolean是否可以拥有多语言值。
requiredboolean是否必填。
validationsarray应用于值的校验规则列表。没有规则时为空数组 []
disabledboolean是否已禁用。
targetTypestring (enum)仅当 typeRefer 时。引用对象是 Content 还是 Media
itemsobject仅当 typeArray 时。数组元素的定义(Refer 元素或 ShortText 元素)。

字段种类 (type)

type 决定值的存储和查询方式。部分类型的搜索行为不同。

type含义备注
ShortText短的单行文本。适合精确关键词查询。
LongText较长的正文文本。支持全文(full-text)相似度搜索。
RichText带格式的正文。不作为搜索对象,用于格式表达。
Long整数。例如价格 price
Number实数(含小数)。
Boolean真/假。
Date日期、时间。
Json任意 JSON 结构。
Location位置(坐标)。
Refer指向其他资源的引用。通过 targetType 指定 ContentMedia
Array容纳多个值的数组。通过 items 附带元素定义。

在 "商品" 示例中,商品名称ShortText价格Long详细说明RichText主图RefertargetType: Media),品牌RefertargetType: Content)。品牌 字段通过 validations 中的 referContentType 限制只能引用特定 Content Type(此处为 "品牌",sys.id3trmXRM3RqbgSnifyg7OveRYWnJWEG)的 Content

可在 validations 中使用的校验规则的完整键目录整理在 CMA Content Type 中。CDA 传递的发布快照也原样携带相同的结构。

API

下面两个端点的基准 URL 是 https://cda.weegloo.com/v1,需要在 Authorization 头中提供认证 CDA 的 Bearer 令牌。由于 Content Type 是框架(schema),不是选择语言的对象,因此与 Content 查询不同,不接受 locale 查询参数。