About metafields and metaobjects
Shopify's platform includes data models for fundamental commerce concepts such as products, collections, and orders out of the box. However, commerce is diverse and often requires more complex or specific data models. The custom data platform enables you to extend Shopify's data models and create your own by using the following resources:
- Metafields: Define and associate custom fields with Shopify resources such as products.
- Metaobjects: Define and create custom data structures within Shopify.
About metafields
Anchor link to section titled "About metafields"Metafields are a flexible way for your app to add and store additional information about a Shopify resource, such as a product, a collection, and many other owner types. 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.
How metafields work
Anchor link to section titled "How metafields work"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.
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 following example shows the structure of the instructions.wash
metafield:
The following example shows the structure of the instructions.dry
metafield:
Kinds of metafields
Anchor link to section titled "Kinds of metafields"You can create different kinds of metafields:
- Regular metafields: Add and store additional information about a Shopify resource.
- Private metafields: Create metafields that aren't accessible to merchants or other apps.
- App-data metafields: Create metafields that belong to an app installation and are only accessible by that app.
Metafield definitions
Anchor link to section titled "Metafield definitions"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. Learn about the standard metafield definitions we offer.
Metafield types
Anchor link to section titled "Metafield types"Each metafield and metafield definition has a type, which defines the type of information that it can store. The metafield types have built-in validation and Liquid support.
For more information about the supported types, refer to Metafield types.
About metaobjects
Anchor link to section titled "About metaobjects"Metaobjects are custom data structures that your app can define and create to store your app's information. Similar to metafields, they can be associated with a Shopify resource such as a product or a collection. However, they can also exist on their own. Metaobjects provide you with a way to create resources that Shopify doesn't offer out of the box.
Users can define their own metaobjects or use the ones that your app creates to extend their shop's data model. Metaobjects are also available in themes using Liquid, Storefront API, and Admin API.
Metaobject definitions and entries
Anchor link to section titled "Metaobject definitions and entries"The following terms are used when describing metaobjects:
- Definition: A template for which fields and properties you want to declare for your metaobjects.
- Entry: A metaobject entry created using a definition.
Metaobject example
Anchor link to section titled "Metaobject example"In the following GraphQL examples, a user wants to create a new resource in Shopify called Product Highlight
. A product highlight has a title, description and image that displays an interesting fact about a product.
The following examples shows the structure of the Product Highlight
metaobject definition:
The following example shows a Product Highlight
metaobject entry:
Developer tools and resources
Anchor link to section titled "Developer tools and resources"Explore the following developer tools and resources for working with metafields and metaobjects:
Metaobjects
Anchor link to section titled "Metaobjects"- Learn how to own the custom objects and fields that your app defines in Shopify.
- Learn about all of the different types supported by metafields.
- Learn how to manage metafields using the GraphQL Admin API.
- Use metafields to link product options to the Shopify taxonomy.
- Learn how to work with metaobjects using the GraphQL Admin API.