1 {"slug":"/references/workflows/createStep","title":"createStep - Workflows SDK Reference","frontmatter":{"slug":"/references/workflows/createStep","sidebar_label":"createStep"},"toc":[{"title":"Example","id":"example","level":2},{"title":"Type Parameters","id":"createstep-type-parameters","level":2},{"title":"Parameters","id":"createstep-parameters","level":2},{"title":"Returns","id":"createstep-returns","level":2}],"blocks":[{"kind":"markdown","html":"This documentation provides a reference to the `createStep` . It belongs to the Workflows SDK."},{"kind":"markdown","html":"This function creates a [StepFunction](/references/workflows/types/workflows.StepFunction) that can be used as a step in a workflow constructed by the [createWorkflow](/references/workflows/createWorkflow) function."},{"kind":"heading","level":2,"text":"Example","id":"example"},{"kind":"markdown","html":"```ts\nimport {\n createStep,\n StepResponse\n} from \"@medusajs/framework/workflows-sdk\"\n\ninterface CreateProductInput {\n title: string\n}\n\nexport const createProductStep = createStep(\n \"createProductStep\",\n async function (\n input: CreateProductInput,\n { container }\n ) {\n const productModuleService = container.resolve(\n \"product\"\n )\n const product = await productModuleService.createProducts(input)\n return new StepResponse({\n product\n }, {\n product_id: product.id\n })\n },\n async function (\n input,\n { container }\n ) {\n if (!input) {\n return\n }\n const productModuleService = container.resolve(\n \"product\"\n )\n await productModuleService.deleteProducts([input.product_id])\n }\n)\n```"},{"kind":"heading","level":2,"text":"Type Parameters","id":"createstep-type-parameters"},{"kind":"typeList","sectionTitle":"createStep","types":[{"name":"TInvokeInput","type":"`object`","description":"The type of the expected input parameter to the invocation function.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"TInvokeResultOutput","type":"`object`","description":"The type of the expected output parameter of the invocation function.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"TInvokeResultCompensateInput","type":"`object`","description":"The type of the expected input parameter to the compensation function.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":2,"text":"Parameters","id":"createstep-parameters"},{"kind":"typeList","sectionTitle":"createStep","types":[{"name":"nameOrConfig","type":"`string` \\| `object` & Omit<[TransactionStepsDefinition](/references/workflows/types/workflows.TransactionStepsDefinition), \"next\" \\| \"uuid\" \\| \"action\">","description":"The name of the step or its configuration.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"invokeFn","type":"[InvokeFn](/references/workflows/types/workflows.InvokeFn)<TInvokeInput, TInvokeResultOutput, TInvokeResultCompensateInput>","description":"An invocation function that will be executed when the workflow is executed. The function must return an instance of [StepResponse](/references/workflows/classes/workflows.StepResponse). The constructor of [StepResponse](/references/workflows/classes/workflows.StepResponse)\naccepts the output of the step as a first argument, and optionally as a second argument the data to be passed to the compensation function as a parameter.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"compensateFn","type":"[CompensateFn](/references/workflows/types/workflows.CompensateFn)<TInvokeResultCompensateInput>","description":"A compensation function that's executed if an error occurs in the workflow. It's used to roll-back actions when errors occur.\nIt accepts as a parameter the second argument passed to the constructor of the [StepResponse](/references/workflows/classes/workflows.StepResponse) instance returned by the invocation function. If the\ninvocation function doesn't pass the second argument to `StepResponse` constructor, the compensation function receives the first argument\npassed to the `StepResponse` constructor instead.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":2,"text":"Returns","id":"createstep-returns"},{"kind":"typeList","sectionTitle":"createStep","types":[{"name":"StepFunction","type":"[StepFunction](/references/workflows/types/workflows.StepFunction)<TInvokeInput, TInvokeResultOutput>","optional":false,"defaultValue":"","description":"A step function to be used in a workflow.","expandable":false,"children":[]}]}]}