**版本：202201**

# 创建元字段定义

**POST** `/openapi/2022-01/metafield_definition/:owner_resource`

使用提供的详情创建新元字段定义。

## 请求

**Path参数**

- `owner_resource` string (required)

  所属资源类型。

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

**application/json**

**请求体 | 示例**

**请求体**

- `namespace` string (required)

  Namespace of definition
- `key` string (required)

  Key of definition
- `type` string (required)

  Definition field type, choose from `date` `date_time` `weight` `volume` `dimension` `integer` `number_decimal` `file_reference` `single_line_text_field` `json` `multi_line_text_field` `color` `rating` `url` `boolean`
- `name` string (required)

  Name of definition
- `description` string

  Description of definition

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

## 响应

**200 | 422**

200

**application/json**

**数据结构 | 示例 | Result**

**数据结构**

- `id` string

  **示例：** `374034306256875562`
- `key` string

  **示例：** `key2`
- `name` string

  **示例：** `Big`
- `namespace` string

  **示例：** `test`
- `owner_resource` string

  **示例：** `product`
- `type` string

  **示例：** `boolean`
- `description` string

  **示例：** `boolean`
- `create_at` string

  **示例：** `2024-04-28T03:18:59Z`
- `updated_at` string

  **示例：** `2024-04-28T03:18:59Z`

```json
{
  "id": "374034306256875562",
  "key": "key2",
  "name": "Big",
  "namespace": "test",
  "owner_resource": "product",
  "type": "boolean",
  "description": "boolean",
  "create_at": "2024-04-28T03:18:59Z",
  "updated_at": "2024-04-28T03:18:59Z"
}
```

```json
{
  "id": "374034306256875562",
  "key": "key2",
  "name": "Big",
  "namespace": "test",
  "owner_resource": "product",
  "type": "boolean",
  "description": "boolean",
  "create_at": "2024-04-28T03:18:59Z",
  "updated_at": "2024-04-28T03:18:59Z"
}
```

422

**application/json**

**数据结构 | 示例 | Result**

**数据结构**

- `errors` string[]

```json
{
  "errors": [
    "Key is required"
  ]
}
```

```json
{
  "errors": [
    "Key is required",
    "Type is required",
    "Name is required",
    "Type is invalid",
    "Metafield definition namespace and key exist"
  ]
}
```
