Skip to main content
The batch orchestrator behind POST /admin/products/:id/attributes/batch and POST /vendor/products/:id/attributes/batch. Delegates to removeProductAttributesFromProductWorkflow, addProductAttributesToProductWorkflow, and updateProductAttributesOnProductWorkflow, applied in the order remove → add → update so removing and re-adding the same attribute in one call resolves correctly.

Usage

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

await createAndLinkProductAttributesToProductWorkflow(container).run({
  input: {
    product_id: "prod_123",
    add: [{ id: "pattr_color", value_ids: ["pattrval_red"] }],
    remove: ["pattr_old"],
    update: [{ id: "pattr_size", add: ["pattrval_xl"] }],
  },
})

Input

product_id
string
required
The product whose attributes are being managed.
add
ProductAttributeBatchAdd[]
Attributes to attach — existing ({ id, value_ids | value }) or inline ({ title, type?, value | values, is_variant_axis? }).
remove
string[]
Ids of attributes to detach; product-scoped attributes are deleted, shared ones are unlinked.
update
ProductAttributeBatchUpdate[]
Per-attribute selection changes ({ id, title?, add?, remove?, value? }).
additional_data
object
Custom data passed through to the workflow hooks.

Result

result
void
No return value.

Hooks

  • validate — runs before any mutation with { input }; throw to reject the batch.
  • productAttributesLinked — runs after all sub-workflows with { product_id }.
createAndLinkProductAttributesToProductWorkflow.hooks.productAttributesLinked(
  async ({ product_id }) => {
    // re-index the product
  },
)