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(系统属性)之外,还包含 name、displayField、publishWithAuthor、fields 等正文属性。
{
"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.id:Content Type 的唯一标识符。用于填入单条查询路径中的{contentTypeId}。sys.revision:公开时刻的版本。CDA 不携带管理用的version,因此指向发布版本的值只有revision一个。name:Content Type 的名称(例如商品)。displayField:在内容工作室列表中代表每条 Content 显示的字段的apiName(例如productName)。publishWithAuthor:发布 Content 时是否一并携带作者信息(示例为false)。fields:该框架定义的字段列表。各项的结构在下方 字段 中说明。
系统属性 (sys)
已发布 Content Type 的 sys 仅携带发布快照用的属性。space、createdBy、updatedBy 以 Refer 形态({ "sys": { "id", "type": "Refer", "targetType" } })出现。
| 属性 | 类型 | 说明 |
|---|---|---|
id | string | 资源唯一标识符。 |
type | string | 资源种类。Content Type 始终为 "ContentType"。 |
space | Refer<Space> | 该 Content Type 所属的 Space。 |
createdAt | string (date-time) | 创建时间。 |
updatedAt | string (date-time) | 最后修改时间。 |
revision | integer | 公开时刻的版本。每次发布时该时刻的版本都会写入此处。 |
createdBy | Refer<User> | 创建该资源的用户。仅当 Content Type 的 publishWithAuthor 开启时才包含。 |
updatedBy | Refer<User> | 最后修改的用户。仅当 publishWithAuthor 开启时才包含。 |
由于是发布快照,CMA 的 sys 中的 version、status、publish、archive 都不会携带。指向发布版本的值只有 revision 一个。
字段
fields 是该 Content Type 定义的字段列表。每一项具有以下结构(FieldDefinition)。
| 键 | 类型 | 说明 |
|---|---|---|
id | string | 字段的唯一标识符。 |
name | string | 内容工作室中显示的字段名称(例如 商品名称)。 |
apiName | string | API 中指向该字段的键。在已发布 Content 的 fields 中也用此键读取值。 |
type | string (enum) | 字段的类型。参见下方 字段种类 (type)。 |
localized | boolean | 是否可以拥有多语言值。 |
required | boolean | 是否必填。 |
validations | array | 应用于值的校验规则列表。没有规则时为空数组 []。 |
disabled | boolean | 是否已禁用。 |
targetType | string (enum) | 仅当 type 为 Refer 时。引用对象是 Content 还是 Media。 |
items | object | 仅当 type 为 Array 时。数组元素的定义(Refer 元素或 ShortText 元素)。 |
字段种类 (type)
type 决定值的存储和查询方式。部分类型的搜索行为不同。
type | 含义 | 备注 |
|---|---|---|
ShortText | 短的单行文本。 | 适合精确关键词查询。 |
LongText | 较长的正文文本。 | 支持全文(full-text)相似度搜索。 |
RichText | 带格式的正文。 | 不作为搜索对象,用于格式表达。 |
Long | 整数。 | 例如价格 price。 |
Number | 实数(含小数)。 | |
Boolean | 真/假。 | |
Date | 日期、时间。 | |
Json | 任意 JSON 结构。 | |
Location | 位置(坐标)。 | |
Refer | 指向其他资源的引用。 | 通过 targetType 指定 Content 或 Media。 |
Array | 容纳多个值的数组。 | 通过 items 附带元素定义。 |
在 "商品" 示例中,商品名称 为 ShortText,价格 为 Long,详细说明 为 RichText,主图 为 Refer(targetType: Media),品牌 为 Refer(targetType: Content)。品牌 字段通过 validations 中的 referContentType 限制只能引用特定 Content Type(此处为 "品牌",sys.id 为 3trmXRM3RqbgSnifyg7OveRYWnJWEG)的 Content。
可在 validations 中使用的校验规则的完整键目录整理在 CMA Content Type 中。CDA 传递的发布快照也原样携带相同的结构。
API
下面两个端点的基准 URL 是 https://cda.weegloo.com/v1,需要在 Authorization 头中提供认证 CDA 的 Bearer 令牌。由于 Content Type 是框架(schema),不是选择语言的对象,因此与 Content 查询不同,不接受 locale 查询参数。
相关文档
- CMA Content Type:创建和修改 Content Type 的管理 API(包含字段类型、校验的完整规范)。
- CDA Content:接收遵循该框架的已发布 Content。
- 状态与发布 (概念):发布、版本的含义。
