Metafields are a flexible way for your app to add and store additional information about a Shopify resource. If you want to include data validation for metafield values, then you can create metafield definitions.
This guide shows you how to manage metafields using the GraphQL Admin API.
RequirementsAnchor link to section titled "Requirements"
- Your app can make authenticated requests to the GraphQL Admin API.
- You've created products in your store.
Step 1: Create a metafieldAnchor link to section titled "Step 1: Create a metafield"
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 a metafield, 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
Step 2: Retrieve a metafieldAnchor link to section titled "Step 2: Retrieve a metafield"
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
Step 3: Update a metafieldAnchor link to section titled "Step 3: Update a metafield"
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
Step 4: Delete a metafield (optional)Anchor link to section titled "Step 4: Delete a metafield (optional)"
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:
- Create metafield definitions to include data validation for metafield values.
- Learn about access controls for app owned metafields.
- Learn how to migrate your metafields that use the deprecated