Manage metafield definitions
Metafield definitions enable you to include data validation for metafields, and enable users to add metafield values for resources in the Shopify admin. This guide shows you how to manage metafield definitions using the GraphQL Admin API.
Anchor to RequirementsRequirements
- Your app can make authenticated requests to the GraphQL Admin API.
- You're using the GraphQL Admin API version 2021-10 or higher.
- Your app has access to the owner type that you want to associate with the metafield definition. You can only create metafield definitions for owner types that you have access to.
Anchor to Step 1: Create a metafield definitionStep 1: Create a metafield definition
You can create a metafield definition using the metafieldDefinitionCreate
mutation. You can create only one metafield definition at a time.
The following example creates a metafield definition called Ingredients
for the PRODUCT
owner type, which stores multi-line text, such as a list of ingredients used to make the product.
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
Variables
JSON response
Anchor to Step 2: Retrieve a metafield definitionStep 2: Retrieve a metafield definition
You can use the metafieldDefinition
query to retrieve a metafield definition.
The following example retrieves a metafield definition by using its ID:
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL query
Variables
JSON response
Anchor to Step 3: Update a metafield definitionStep 3: Update a metafield definition
You can use the metafieldDefinitionUpdate
mutation to update a metafield definition. You can update only the name and description of a metafield definition.
The following example changes a metafield definition's name from Pizza size
to Pizza size (inches)
:
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
Variables
JSON response
Anchor to Step 4 (Optional): Delete a metafield definitionStep 4 (Optional): Delete a metafield definition
To delete a metafield definition, use the metafieldDefinitionDelete
mutation. You can also set an option that, when selected, deletes all metafields that use that definition.
The following example deletes the metafield definition for bakery.ingredients
, and also deletes all metafields that use the definition.
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
Variables
JSON response
Anchor to Next stepsNext steps
- Learn how to manage validation options using the GraphQL Admin API.
- Learn how to create automated collections with metafield definition conditions.