Skip to main content
In this guide, you’ll learn how to create a global catalog attribute from your own server code, for example in a seed script, a custom API route, or a catalog import. Mercur exposes a createProductAttributesWorkflow that creates one or more ProductAttribute records along with their values. Run it from any place that has access to the Medusa container.

Run the workflow

src/api/custom/attributes/route.ts
The workflow creates the attribute, its ProductAttributeValue records, and, for a multi_select axis, the mirror ProductOption. It also emits the product-attribute.created event.
Leaving product_id unset creates a global attribute reusable across the catalog. Passing a product_id creates an inline attribute scoped to a single product. See Global vs inline.

Associate categories

Pass category_ids on an attribute to associate it with product categories through the category link in the same call:

Attach custom data

The workflow accepts an additional_data payload passed to its productAttributesCreated hook, letting you persist marketplace-specific data alongside the attribute without forking the workflow.