Skip to main content
In this guide, you’ll learn how to manage all of a product’s attributes from server code through a single batch workflow. Mercur exposes createAndLinkProductAttributesToProductWorkflow, the engine behind the product attribute batch endpoint. One call can attach new attributes, detach existing ones, and update selections, applied in the order remove → add → update so a same-call remove and re-add of one attribute resolves correctly.

Run the batch workflow

src/api/custom/products/[id]/attributes/route.ts

The three operations

Each entry in add is one of the ProductAttributeBatchAdd forms: remove takes attribute ids to detach; update carries ProductAttributeBatchUpdate entries adjusting an existing selection.
For a variant-axis attribute, value_ids is the per-product subset of the mirror option’s values. The product’s variants are generated from exactly that subset. See Variant axes.
The batch workflow composes the lower-level addProductAttributesToProductWorkflow, removeProductAttributesFromProductWorkflow, and updateProductAttributesOnProductWorkflow. Reach for those directly when you only need one of the three operations.