Validation Settings API
The Validation Settings API lets you create complex validation rules for cart and checkout validation. Use this API to build custom settings interfaces for Shopify Functions that implement validation logic.
Anchor to Use casesUse cases
- Validation configuration: Build settings interfaces for cart and checkout validation Functions.
- Metafield management: Store and update validation rule configuration in metafields.
- Settings UI: Create custom settings experiences for validation logic configuration.
- Function integration: Configure Shopify Functions that implement validation behavior.
Supported targets
Supported targets
Applies a metafield change to the validation settings. Use this method to update or remove metafields that store validation function configuration data. The method accepts a change object specifying the operation type, metafield key, namespace, value, and value type. Returns a promise that resolves to indicate success or provides an error message if the operation fails.
- Anchor to changechangechangeMetafieldChangeMetafieldChangerequiredrequired
MetafieldChange
A metafield change operation that can either update or remove a metafield. Pass this to `applyMetafieldChange` to modify discount settings stored in metafields.
MetafieldUpdateChange | MetafieldRemoveChangeMetafieldUpdateChange
A metafield update or creation operation. Use this to set or modify metafield values that store discount function configuration data.
- key
The unique key identifying the metafield within its namespace. Use descriptive keys that indicate the setting's purpose (for example, `'min_purchase_amount'` or `'eligible_customer_tags'`).
string - namespace
The namespace that organizes related metafields. When omitted, a default namespace is assigned. Use consistent namespaces to group related settings.
string - type
Identifies this as an update operation. Always set to `'updateMetafield'` for updates.
'updateMetafield' - value
The metafield value to store. Can be a string or number depending on your configuration needs.
string | number - valueType
The [data type](/docs/apps/build/metafields/list-of-data-types) that defines how the value is formatted and validated. When omitted, preserves the existing type for updates or uses a default for new metafields. Choose a type that matches your value format.
SupportedDefinitionType
SupportedDefinitionType
The supported [metafield definition types](/docs/apps/build/metafields/list-of-data-types) for storing extension configuration data. Use these types to specify how metafield values should be formatted, validated, and displayed. Types prefixed with `list.` store arrays of values, while other types store single values. Choose a type that matches your data format (for example, use `'number_integer'` for whole numbers, `'single_line_text_field'` for short text, or `'json'` for complex structured data).
'boolean' | 'collection_reference' | 'color' | 'date' | 'date_time' | 'dimension' | 'file_reference' | 'json' | 'metaobject_reference' | 'mixed_reference' | 'money' | 'multi_line_text_field' | 'number_decimal' | 'number_integer' | 'page_reference' | 'product_reference' | 'rating' | 'rich_text_field' | 'single_line_text_field' | 'product_taxonomy_value_reference' | 'url' | 'variant_reference' | 'volume' | 'weight' | 'list.collection_reference' | 'list.color' | 'list.date' | 'list.date_time' | 'list.dimension' | 'list.file_reference' | 'list.metaobject_reference' | 'list.mixed_reference' | 'list.number_decimal' | 'list.number_integer' | 'list.page_reference' | 'list.product_reference' | 'list.rating' | 'list.single_line_text_field' | 'list.url' | 'list.variant_reference' | 'list.volume' | 'list.weight'MetafieldRemoveChange
A metafield removal operation. Use this to delete metafields that are no longer needed for your discount configuration.
- key
The unique key of the metafield to remove. Must match the key used when the metafield was created.
string - namespace
The namespace containing the metafield to remove. Required to ensure the correct metafield is targeted, as the same key can exist in different namespaces.
string - type
Identifies this as a removal operation. Always set to `'removeMetafield'` for deletions.
'removeMetafield'
MetafieldChangeResult
The result returned after attempting to change a metafield. Check the `type` property to determine if the operation succeeded (`'success'`) or failed (`'error'`), then handle the result appropriately in your extension.
MetafieldChangeSuccess | MetafieldChangeResultErrorMetafieldChangeSuccess
A successful metafield change operation result. The metafield was updated or removed as requested and the changes are now saved.
- type
Indicates the operation succeeded. When this value is `'success'`, the metafield change was applied successfully.
'success'
MetafieldChangeResultError
A failed metafield change operation result. Use the error message to understand what went wrong and fix the issue, such as validation errors, permission problems, or invalid metafield types.
- message
A human-readable error message explaining why the operation failed. Use this to debug issues or display feedback to merchants.
string - type
Indicates the operation failed. Check this value to determine if you need to handle an error.
'error'
Anchor to datadata
The data object exposed to the extension containing the validation settings. Provides access to the validation object with its identifier and metafields, plus the Shopify Function identifier. Use this data to populate your settings UI and understand the current validation configuration in the admin.settings.validation.render target.
- Anchor to shopifyFunctionshopifyFunctionshopifyFunctionShopifyFunctionShopifyFunctionrequiredrequired
The Shopify Function that implements the validation logic. Use this ID to associate configuration changes with the correct function.
- Anchor to validationvalidationvalidationValidationValidation
The validation configuration containing the validation ID and metafields. Present when editing an existing validation, absent when creating a new validation. Use the presence of this value to determine if you're in create or edit mode.
ShopifyFunction
A [Shopify Function](/docs/apps/build/functions) that implements cart and checkout validation logic. This identifies which function the settings interface is configuring.
- id
The [Shopify Function's](/docs/apps/build/functions) unique global identifier (GID). Use this ID to associate settings changes with the correct function.
string
Validation
A validation configuration that exists and is active in the shop. Use this object to access the validation's current settings and metafields when merchants edit an existing validation.
- id
The validation's unique global identifier (GID). Use this ID to reference the validation in GraphQL operations or when saving updated settings.
string - metafields
An array of [metafields](/docs/apps/build/metafields) that store the validation's configuration values. Use these metafields to populate your settings UI with the current validation configuration.
Metafield[]
Metafield
A [metafield](/docs/apps/build/metafields) that stores discount function configuration data. Use metafields to persist settings that control how your discount function behaves, such as discount thresholds, eligibility rules, or custom discount logic parameters.
- description
A human-readable description explaining the metafield's purpose and how it affects discount behavior. Use this to document your settings for other developers.
string - id
The unique global identifier (GID) for this metafield. Use this ID to reference the metafield in GraphQL queries or updates.
string - key
The unique key identifying this metafield within its namespace. This key determines how you access the metafield value (for example, `'min_purchase_amount'` or `'eligible_customer_tags'`).
string - namespace
The namespace that organizes related metafields together. All metafields for a discount should use a consistent namespace to group related settings.
string - type
The metafield [definition type](/docs/apps/build/metafields/list-of-data-types) that specifies the value format and validation rules. Use this to determine how to parse and display the value.
string - value
The metafield value stored as a string. Parse this value according to the metafield type to use it in your settings UI.
string
Anchor to Best practicesBest practices
- Check operation result type:
applyMetafieldChangereturns{ type: 'success' }or{ type: 'error', message: string }. Errors don't throw exceptions, so always check the returnedtypeproperty.
Anchor to LimitationsLimitations
- Metafields have size limits. Individual values can't exceed 256KB, and total metafield storage per validation is limited.
- The
applyMetafieldChangemethod is sequential. Operations process one at a time. Rapid successive calls can cause race conditions where later updates overwrite earlier ones. - Metafield changes apply immediately. Unlike admin forms, metafield changes persist right away without waiting for merchants to save.
- Your extension can't modify the Function ID. The
shopifyFunctionIdis read-only and determined when the validation rule is created.