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.
Requirements
Anchor link to section titled "Requirements"- 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 namespace and the owner type that you want to associate with the metafield definition. You can only create metafield definitions for namespaces and owner types that you have access to.
Step 1: Create a metafield definition
Anchor link to section titled "Step 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.
Step 2: Retrieve a metafield definition
Anchor link to section titled "Step 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:
Step 3: Update a metafield definition
Anchor link to section titled "Step 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)
:
Step 4 (Optional): Delete a metafield definition
Anchor link to section titled "Step 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.
- Learn how to manage validation options using the GraphQL Admin API.
- Learn how to create automated collections with metafield definition conditions.