Overview
Workflow hooks are specific points in Medusa’s core workflows where you can inject custom functionality. Learn more about workflow hooks in Medusa’s documentation. The hooks documented below extend Medusa’s core commerce workflows to add marketplace-specific functionality such as seller associations, inventory management, secondary categories, and search index synchronization.Product Hooks
createProductsWorkflow.hooks.productsCreated
This hook handler extends Medusa’screateProductsWorkflow to add marketplace-specific functionality when products are created.
Source code
Functionality
- Links products to sellers
- Links inventory items to sellers
- Creates and links secondary categories
- Assigns default seller shipping profiles
- Emits
products.changedevent for Algolia indexing - Handles attribute value creation for products
Hook Input
Array of created products.
Additional data passed from API route or workflow.
Compensation
The hook includes a compensation function that dismisses all created product links if a subsequent step fails.updateProductsWorkflow.hooks.productsUpdated
This hook handler extends Medusa’supdateProductsWorkflow to update marketplace-specific relationships and trigger search index updates when products are updated.
Source code
Functionality
- Updates attribute values for products
- Manages secondary category links (add/remove)
- Emits
products.changedevent for Algolia indexing
Hook Input
Array of updated products.
Additional data passed from API route or workflow.
deleteProductsWorkflow.hooks.productsDeleted
This hook handler extends Medusa’sdeleteProductsWorkflow to trigger search index updates when products are deleted.
Source code
Functionality
- Emits
products.deletedevent for Algolia index removal
Hook Input
Array of deleted product IDs.
createProductVariantsWorkflow.hooks.productVariantsCreated
This hook handler extends Medusa’screateProductVariantsWorkflow to link newly created variants’ inventory items to sellers.
Source code
Functionality
- Links inventory items to sellers for variants with inventory management enabled
Hook Input
Array of created product variants.
Additional data passed from API route or workflow.
updateProductVariantsWorkflow.hooks.productVariantsUpdated
This hook handler extends Medusa’supdateProductVariantsWorkflow to trigger search index updates for products when their variants are updated.
Source code
Functionality
- Emits
products.changedevent for Algolia indexing of affected products
Hook Input
Array of updated product variants (includes product_id).
updateCollectionsWorkflow.hooks.collectionsUpdated
This hook handler extends Medusa’supdateCollectionsWorkflow to trigger search index updates for products when their collections are updated.
Source code
Functionality
- Emits
products.changedevent for Algolia indexing of products in updated collections
Hook Input
Array of updated collections (includes products array).
updateProductOptionsWorkflow.hooks.productOptionsUpdated
This hook handler extends Medusa’supdateProductOptionsWorkflow to trigger search index updates for products when their options are updated.
Source code
Functionality
- Emits
products.changedevent for Algolia indexing of affected products
Hook Input
Array of updated product options (includes product_id).
updateProductTagsWorkflow.hooks.productTagsUpdated
This hook handler extends Medusa’supdateProductTagsWorkflow to trigger search index updates for products when their tags are updated.
Source code
Functionality
- Emits
products.changedevent for Algolia indexing of products with updated tags
Hook Input
Array of updated product tags (includes products array).
Order Hooks
createOrderShipmentWorkflow.hooks.shipmentCreated
This hook handler extends Medusa’screateOrderShipmentWorkflow to automatically complete orders when shipments are created and payment has been captured.
Source code
Functionality
- Retrieves order details from the fulfillment
- Checks if payment status is “captured”
- Automatically completes the order if payment is captured
Hook Input
The created shipment (fulfillment) object.
Usage Examples
Accessing Hook Handlers
Hook handlers are automatically registered when the Medusa application starts. They’re defined in files undersrc/workflows/hooks/ and consume hooks from Medusa’s core workflows.
For example, the product creation hook in action:
packages/modules/b2c-core/src/workflows/hooks/product-created.ts
Passing Additional Data
To pass additional data (likeseller_id) to hook handlers, include it when calling the workflow: