Metafields are a flexible way for your app to add and store additional information about a Shopify resource, such as a product or a collection. The additional information stored in metafields can be almost anything related to a resource. Some examples are specifications, size charts, downloadable documents, release dates, images, or part numbers. Merchants and other apps can retrieve and edit the data that's stored in metafields from the Shopify admin. You can also access metafields in themes using Liquid and through the Storefront API.
Metafield definitions enable you to include data validation for metafields, and enable merchants to add metafield values for resources in the Shopify admin. We also provide standard metafield definitions for common use cases. Using standard definitions means that your app can access information that merchants might have already stored in these metafields and provides interoperability across the Shopify platform.
If you don't want metafield data to be accessible to merchants and other apps, then you can use private metafields.
Metafield structureAnchor link to section titled "Metafield structure"
A metafield includes the following parts:
- Namespace: A container for a group of metafields. Grouping metafields within a namespace prevents your metafields from conflicting with other metafields with the same key name.
- Key: The name for the metafield.
Type: The type of data that the metafield stores.
Value: The data to store in the metafield. The value is always stored as a string, regardless of the metafield's type.
Metafield structure examplesAnchor link to section titled "Metafield structure examples"
In the following GraphQL examples, a merchant that sells clothing uses metafields to store the care instructions for each product. The online store has separate metafields for washing and drying instructions, which are grouped by the
instructions namespace. Each product can have a different value for each metafield. A metafield set includes all the data for a particular metafield.
The structure of the
The structure of the
Developer resources for metafieldsAnchor link to section titled "Developer resources for metafields"
- GraphQL Admin API: Supports creating, retrieving, updating, and deleting metafield definitions, metafields, and private metafields. For more information, refer to the metafield reference for the GraphQL Admin API.
- REST Admin API: Supports creating, retrieving, updating, and deleting metafields. For more information, refer to the metafield reference for the REST Admin API.
- Storefront API: Supports retrieving metafields.
- Themes: Access the metafield object, and use metafield filters to output metafield data, in themes using Liquid.