createHook - Workflows API Reference

This documentation provides a reference to the createHook . It belongs to the @medusajs/framework/workflows-sdk package.

Expose a hook in your workflow where you can inject custom functionality as a step function.

A handler hook can later be registered to consume the hook and perform custom functionality.

Learn more in this documentation.

Example#

Code
1import {2  createStep,3  createHook,4  createWorkflow,5  WorkflowResponse,6} from "@medusajs/framework/workflows-sdk"7import { createProductStep } from "./steps/create-product"8
9export const myWorkflow = createWorkflow(10  "my-workflow",11  function (input) {12    const product = createProductStep(input)13    const productCreatedHook = createHook(14      "productCreated",15      { productId: product.id }16    )17
18    return new WorkflowResponse(product, {19      hooks: [productCreatedHook],20    })21  }22)

Type Parameters#

NamestringOptional
TInvokeInputobjectOptional

Parameters#

nameName
The hook's name. This is used when the hook handler is registered to consume the workflow.
inputTInvokeInput
The input to pass to the hook handler.

Returns#

HookHook<Name, TInvokeInput>
A workflow hook.
Was this page helpful?