Create Metafield Definition

Create a new metafield definition for a specific resource (e.g., product, product_variant, collection).

This API is especially useful for:

  1. Adding custom fields to extend store data.
  2. Defining custom attributes for products, variants, or collections.
  3. Managing resource metadata efficiently.

Note: The operation is scoped to a specific shop, identified by its unique domain prefix (shopdomain), ensuring all updates are applied to the correct store.

Request Parameters

Public Request Parameters

📘

Public Request Parameters

Path Parameters

ParameterTypeRequiredDescriptionExample
owner_resourcestringYesThe type of resource that the metafield is attached to. Available resources: shop, product, product_image, product_variant, order, page, customer, collection, blog, article.product_variant

Body Parameters

FieldTypeRequiredExampleDescription
namespacestringYescustomNamespace to group metafield definitions.
keystringYescolor_codeUnique key to identify the metafield.
namestringYesProduct ColorName or title for the metafield definition.
descriptionstringNoCustom field for colorBrief description of the metafield definition.
typestringYessingle_line_text_field Field type for the metafield. Valid Values for type:

- date
- date_time
- weight
- volume
- dimension
- integer
- number_decimal
- file_reference
- single_line_text_field
- multi_line_text_field
- json
- color
- rating
- url
- boolean

Response Explanation

Public Response Parameters

📘

Public Response Parameters

Successful Response

FieldTypeExampleDescription
idstring374034306256875562Unique identifier for the metafield definition.
keystringkey2Unique key for the metafield.
namestringBigName or title of the metafield definition.
namespacestringtestNamespace of the metafield definition.
owner_resourcestringproductResource type the metafield is associated with.
typestringbooleanField type for the metafield.
descriptionstringbooleanDescription of the metafield definition.
create_atstring2024-04-28T03:18:59ZTimestamp of when the metafield was created.
updated_atstring2024-04-28T03:18:59ZTimestamp of the last update for the metafield.

Error Response

Error responses in the API can be represented using two different fields: errors and error. Both fields provide details about issues encountered during request processing. Below is an explanation of the fields with their respective examples and descriptions.

FieldTypeExampleDescription
errorsarray["Type is invalid"]A list of errors encountered during the request processing.
FieldTypeExampleDescription
errorString "store is not active"Indicates an error encountered during the process

Error Detail

Status CodeMessagePossible ReasonExample Response
400Bad RequestInvalid input format or request structure (e.g., missing required fields or incorrect data types).Bad Request
UnauthorizedThe request is missing valid authentication credentials or the credentials provided are invalid.Unauthorized
422"Key is required"empty keyKey is required
Type is requiredempty typeType is required
Name is requiredempty nameName is required
Type is invalidtype is not acceptableType is invalid
Owner resource is invalid"Owner resource is not acceptable"Owner resource is invalid"
Metafield definition namespace and key existMetafield definition namespace and key exist"Metafield definition namespace and key exist"

API Structure Overview

Language
Credentials
Header
URL
Click Try It! to start a request and see the response here!