Manage metafields
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.
Requirements
Anchor 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 metafield
Anchor 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 productUpdate
mutation:
Step 2: Retrieve a metafield
Anchor 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 namespace
and key
arguments.
The following example queries a product for the value of the associated instructions.wash
metafield:
Step 3: Update a metafield
Anchor 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 productUpdate
mutation:
Step 4 (Optional): Delete a metafield
Anchor link to section titled "Step 4 (Optional): Delete a metafield"Use the 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.
- Use metafields to manage meta tags for SEO and change the way a store's pages appear in search engine results.
- Learn how to migrate your metafields that use the deprecated
value_type
field.