**版本：202607**

# 创建元字段

**POST** `/openapi/2026-07/metafields/:owner_resource/:owner_id`

根据提供的信息为指定资源创建元字段。

## 请求

**Path参数**

- `owner_resource` string (required)

  所属资源类型：

  *   `shop`: 店铺
  *   `product`: 商品
  *   `product_image`: 商品图片
  *   `product_variant`: 商品款式
  *   `order`: 订单
  *   `page`: 自定义页面
  *   `customer`: 顾客
  *   `collection`: 商品专辑
  *   `blog`: 博客
  *   `article`: 文章
  *   `app`: 应用
- `owner_id` string (required)

  所属资源的 ID

**application/json**

**请求体 | 示例**

**请求体 (required)**

- `definition_id` string (required)

  关联的元字段定义 ID
- `namespace` string (required)

  命名空间
- `key` string (required)

  元字段键名
- `value` GoogleProtobufValue (required)

  元字段值；其数据类型由 `type` 字段决定（例如 `{ "mediaContentType": "IMAGE", "image": { "path": "xxx.jpg", "alt": "", "width": 750, "height": 750, "src": "https://cdn.shoplazza.com/xxx.jpg", "size": 775566 } }`）
- `type` string (required)

  元字段值类型：

  *   `date`: 日期
  *   `date_time`: 日期和时间
  *   `weight`: 重量
  *   `volume`: 体积
  *   `dimension`: 外形尺寸
  *   `integer`: 整数
  *   `number_decimal`: 小数
  *   `file_reference`: 文件引用
  *   `single_line_text_field`: 单行文本
  *   `multi_line_text_field`: 多行文本
  *   `json`: JSON
  *   `color`: 颜色
  *   `rating`: 评分
  *   `url`: URL
  *   `boolean`: 布尔值（true 或 false）
- `description` string

  元字段描述

```json
{
  "definition_id": "string",
  "namespace": "string",
  "key": "string",
  "type": "string",
  "description": "string"
}
```

## 响应

**200**

OK

**application/json**

**数据结构 | 示例**

**数据结构**

- `code` string

  错误码
- `message` string

  错误信息
- `data` object

  - `metafield` object

    已创建的元字段

    - `id` string

      元字段 ID
    - `store_id` uint32

      所属店铺 ID
    - `owner_resource` string

      所属资源类型：

      *   `shop`: 店铺
      *   `product`: 商品
      *   `product_image`: 商品图片
      *   `product_variant`: 商品款式
      *   `order`: 订单
      *   `page`: 自定义页面
      *   `customer`: 顾客
      *   `collection`: 商品专辑
      *   `blog`: 博客
      *   `article`: 文章
      *   `app`: 应用
    - `owner_id` string

      所属资源的 ID（如商品 ID）
    - `namespace` string

      命名空间
    - `key` string

      元字段键名
    - `type` string

      元字段值类型：

      *   `date`: 日期
      *   `date_time`: 日期和时间
      *   `weight`: 重量
      *   `volume`: 体积
      *   `dimension`: 外形尺寸
      *   `integer`: 整数
      *   `number_decimal`: 小数
      *   `file_reference`: 文件引用
      *   `single_line_text_field`: 单行文本
      *   `multi_line_text_field`: 多行文本
      *   `json`: JSON
      *   `color`: 颜色
      *   `rating`: 评分
      *   `url`: URL
      *   `boolean`: 布尔值（true 或 false）
      *   `string`: 字符串
    - `value` GoogleProtobufValue

      元字段值；其数据类型由 `type` 字段决定（例如 `red`）
    - `description` string

      元字段描述（例如 `商品颜色`）
    - `definition_id` uint64

      关联的元字段定义 ID（例如 `123456`）
    - `created_at` string

      创建时间（ISO-8601 格式）
    - `updated_at` string

      最后更新时间（ISO-8601 格式）

```json
{
  "code": "string",
  "message": "string",
  "data": {
    "metafield": {
      "id": "string",
      "store_id": 0,
      "owner_resource": "string",
      "owner_id": "string",
      "namespace": "string",
      "key": "string",
      "type": "string",
      "description": "string",
      "definition_id": 0,
      "created_at": "string",
      "updated_at": "string"
    }
  }
}
```
