新增字段,必填字段未确认时只返回预览,不会写入
POST/api/v1/catalogs/{id}/fields
| 认证 | 请求头 Authorization: Bearer <访问令牌>,访问令牌用设备码换取,不要向用户要密码、短信验证码或 API Key |
|---|---|
| 权限 | 商家,需要 field:write 才能新增或变更目录字段 |
路径参数
path
idstring必填目录 ID
路径示例
/api/v1/catalogs/cat_example/fields请求体
application/json
新增字段,必填且未确认时只返回预览
keystring必填小写字母开头,只能含小写字母、数字和下划线
取值范围: 1 <= 字符数 <= 64
labelstring必填显示名
取值范围: 1 <= 字符数 <= 80
typeenum<string>必填字段类型
可选值: textnumberbooleansingle-select
requiredboolean省略时不是必填
choicesstring[]single-select 必须带,且至少一项
confirmboolean破坏性新增要写成 true 才会写入
请求示例
{
"key": "weight_g",
"label": "示例",
"type": "text",
"required": false,
"choices": [
"string"
],
"confirm": false
}响应
201
application/json
HTTP 201 不表示已写入,先看 data.applied。未确认的破坏性变更带 breaking
appliedboolean必填true 才表示已写入,false 只是预览
breakingboolean未确认的破坏性变更时为 true。已写入时不返回
revisioninteger写入后的字段版本
affected_countinteger必填受影响商品数
fieldobject | null写入后的字段,预览时可能没有
affected[].product_idstring将被下架或已下架的商品 ID
affected[].reasonstring影响原因
响应示例
{
"applied": true,
"breaking": false,
"revision": 1,
"affected_count": 1,
"field": null,
"affected": [
{
"product_id": "prd_example",
"reason": "string"
}
]
}