Skip to main content

Validation Settings API

Requires the function settings component.

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.

  • 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.
Support
Targets (1)

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 change
change
required

Promise<>

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 shopifyFunction
shopifyFunction
required

The Shopify Function that implements the validation logic. Use this ID to associate configuration changes with the correct function.

Anchor to validation
validation

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.


  • Check operation result type: applyMetafieldChange returns { type: 'success' } or { type: 'error', message: string }. Errors don't throw exceptions, so always check the returned type property.

  • Metafields have size limits. Individual values can't exceed 256KB, and total metafield storage per validation is limited.
  • The applyMetafieldChange method 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 shopifyFunctionId is read-only and determined when the validation rule is created.

Was this page helpful?