Skip to main content
Creates product attributes and their values. Variant-axis multi_select attributes also get a shared mirror ProductOption created, with each value bound to its option value. Optional category_ids create category links per attribute. Triggered by POST /admin/product-attributes. Emits product-attribute.created.

Usage

import { createProductAttributesWorkflow } from "@mercurjs/core/workflows"

const { result } = await createProductAttributesWorkflow(container).run({
  input: {
    attributes: [
      {
        name: "Color",
        type: "multi_select",
        is_variant_axis: true,
        values: [{ name: "Red" }, { name: "Blue" }],
        category_ids: ["pcat_apparel"],
      },
    ],
  },
})

Input

attributes
(CreateProductAttributeDTO & { category_ids?: string[] })[]
required
Attributes to create.
additional_data
object
Custom data passed through to the hooks.

Result

result
ProductAttributeDTO[]
The created attributes.

Hooks

  • validate — runs before creation with { input }.
  • productAttributesCreated — runs after creation with { attributes, additional_data }.