When you create your app, you can use metafields to attach specialized information to Shopify resources, such as part numbers or release dates.
Merchants and other apps can retrieve and edit the data that's stored in metafields from the Shopify admin. If you want to use metafields to store data, but you don't want merchants or other apps to access that data, then you can use private metafields.
Metafield definitions enable you to create additional data constraints for metafields, and enable the merchant to edit metafield values in context. Where possible, you should adopt standard metafields, so that your app can access information that merchants have already stored in standard metafields. You can also create your own custom metafield definitions.
Shopify APIs that support metafields
The GraphQL Admin API and REST Admin API support creating, retrieving, updating, and deleting metafields. The Storefront API only supports retrieving metafields. You can also access metafields using Liquid.
Structure of a metafield
|namespace||A container for a group of metafields. Grouping metafields within a namespace prevents your metafields from conflicting with others.|
|key||The identifier for the metafield value.|
|value||The information to be stored in the metafield. The value is always stored as a string, regardless of the metafield's type.|
|type||The data type of the metafield's value. Refer to the list of available types.|
|definition||Optional. The definition contains optional validation rules for a namespace and key. By blocking values that don’t conform to the rules, a definition enforces data consistency across an entire metafield set.|
For example, a clothing shop might use metafields to store the care instructions for its clothing products. The shop could create separate metafields for washing and drying instructions, and then group them by using the namespace
instructions. The following example shows a metafield for washing instructions:
Metafields are visible to all apps as well as to merchants. If you want to restrict the visibility of the data that you're adding to a resource, then you can use private metafields.
Only the GraphQL Admin API supports private metafields.