createAndLinkProductAttributesToProductWorkflow, the same engine behind the admin attribute batch route.
Before you begin
You need the following:- A product: the id of a product in the shared catalog, such as
prod_01JD8Q1234567 - Global attributes: the ids of the catalog attributes and values you want to attach, created as in Create a catalog attribute
Run the batch workflow
1
Send add, remove, and update in one input
The workflow applies The first entry picks a value of a select attribute, the second sets a
remove, then add, then update, so removing and re-adding the same attribute in one run works.src/api/admin/catalog-import/products/[id]/route.ts
unit attribute to 400, and the third creates an inline toggle attribute on this product.2
Read the attributes back
A product holds its selections as linked values. Read them through the Inline attributes also show up under
product_attribute_values link, and read inline attributes through scoped_attributes.product_attribute_values, because their values link to the product the same way.Choose the add form
Eachadd entry is a ProductAttributeBatchAdd. The keys you pass decide what the workflow does:
Change a selection with update
Anupdate entry targets one attribute by id. What add and remove mean depends on the attribute:
- Global select or axis:
addandremovehold attribute value ids, and an axis also moves the option values - Global select or axis, full set:
value_idsis the complete set the product should hold, and the workflow works out the difference - Inline axis:
addholds new values such as{ value: "XL" }, andremoveholds attribute value ids to delete - Text, unit, or toggle:
valuereplaces the current value - Inline rename:
titlerenames an inline attribute, and it’s ignored for global ones
Handle a required attribute
Removing an attribute withis_required: true fails with a NOT_ALLOWED error, and nothing in the run is applied. The check skips attributes you remove and re-add in the same run, so you can replace a required attribute’s selection in one call.
Route vendor edits through review
Running the batch workflow writes to the product immediately. For changes a store makes, runproductEditUpdateAttributesWorkflow with the same add, remove, and update plus created_by. It stages a product change for review, and the change runs the batch workflow when it’s confirmed. See Product edits.