Skip to content

Metafield definitions

View as Markdown

A Metafield definition declares a custom field you can attach to a resource. It sets the field’s namespace and key (which together identify it), the ownerType it applies to (such as product), the type of data it holds, and any validations and constraints that values must satisfy.

Definitions are the schema; the actual values are Metafields stored on individual owner records. Define a field once, then set its value on each product, variant, and so on.

PropertyTypeRequiredDescription
idstring-The resource's unique identifier (UUID).
namestring-The human-readable name of the metafield definition.
descriptionstring | null-The description of the metafield definition.
namespacestring-The container for a group of metafields that the metafield definition is associated with.
keystring-The unique identifier for the metafield definition within its namespace.
ownerTypestringrequiredThe resource type that the metafield definition is attached to.
typestringrequiredThe type of data that each of the metafields that belong to the metafield definition will store.
createdAtstring-The date and time when the resource was created (ISO 8601 format).
updatedAtstring-The date and time when the resource was last modified (ISO 8601 format).
validationsEmbeddedMetafieldDefinitionValidationResource[]-The validation rules applied to the values of metafields using this definition.
Show validations fields
PropertyTypeRequiredDescription
namestringrequiredThe type of validation rule
valuestringrequiredThe validation parameter value. Format depends on the validation type.
constraintsEmbeddedMetafieldDefinitionConstraintResource[]-The constraint rules scoping where this metafield definition applies (e.g. by category or channel).
Show constraints fields
PropertyTypeRequiredDescription
keystringrequiredThe type of constraint rule
valuesstring[]requiredArray of constraint values. Format depends on the constraint type.
metafieldsCountinteger-The count of the metafields that belong to the metafield definition.
  • Add a custom field. Create a definition with a namespace, key, ownerType and type, then set Metafield values on records of that owner type.
  • Constrain values. Attach validations (for example a maximum length or a numeric range) so invalid values are rejected when a metafield is written.
  • Audit usage. Each definition reports a metafieldsCount - how many records currently carry a value for it.

Which validations and constraints you can attach is not free-form - it depends on the definition’s type, and the API rejects an incompatible combination with 422 Unprocessable Entity. The rules differ for the two:

  • Validations depend on the type. A number_decimal accepts numeric validations (min_value, max_value, max_precision); a text type accepts min_length / max_length; a json type accepts json_schema; reference types accept none. The authoritative, always-current list for each type is the allowedValidations field on Metafield definition types - query that resource rather than hard-coding a table.
  • Constraints depend on the ownerType, not the type. Constraints (category, channel, category_channel) are scoped to the owner resource. Today only products allows constraints; every other owner type allows none. The authoritative list is the allowedConstraints field on Metafield owner types.

[!TIP] Before creating a definition, read the matching definition type and owner type to see exactly what it accepts. That way your validations and constraints are valid by construction.

Submitting an incompatible rule returns 422 with a message such as Validation "min_value" is not compatible with metafield definition type "single_line_text_field". or Constraint "category" is not compatible with owner type "variants".

All requests require an OAuth 2.0 bearer token and the organization scope header:

Authorization: Bearer <token>
X-Flowkiwi-Organization-Id: <organization-id>

PATCH uses JSON Merge Patch with Content-Type: application/merge-patch+json.