Create and manage metafields
This section describes how to use the GraphQL Admin API to create and manage metafields. To learn about creating and managing metafields using the REST Admin API, refer to the Metafield resource documentation.
If you want to include data validation for metafield values, then you can create metafield definitions. If you want metafields that aren't accessible to merchants or other apps, then you can create private metafields.
If you need to update your metafields that use the deprecated
value_type field, refer to Metafield
Create metafieldsAnchor link to section titled "Create metafields"
You can create any number of metafields for a resource, and they'll be accessible to any app (unless they're private metafields). To create metafields, use a GraphQL mutation to create or update the resource that you want the metafields to belong to.
The following example adds a metafield to a product by using the
Retrieve metafieldsAnchor link to section titled "Retrieve metafields"
When you query a resource, you can retrieve its metafields. Use the
metafield field to return a single metafield. Specify the metafield that you want to retrieve by using the
The following example queries a product for the value of the associated
Update metafieldsAnchor link to section titled "Update metafields"
To update a metafield, use a GraphQL mutation to update the owning resource, and include the metafield in the mutation input. Specify the owning resource and the metafields that you're updating by their IDs.
The following example updates a metafield that belongs to a product by using the
Delete metafieldsAnchor link to section titled "Delete metafields"
metafieldDelete mutation to delete a metafield. Specify the metafield that you want to delete by including its ID in the mutation input.
The following example deletes a metafield by ID: