- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
Menu
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
createWorkflow - Workflows API Reference
This documentation provides a reference to the createWorkflow
. It belongs to the @medusajs/framework/workflows-sdk
package.
This function creates a workflow with the provided name and a constructor function.
The constructor function builds the workflow from steps created by the createStep function.
The returned workflow is an exported workflow of type ReturnWorkflow, meaning it's not executed right away. To execute it,
invoke the exported workflow, then run its run
method.
Example#
1import {2 createWorkflow,3 WorkflowResponse4} from "@medusajs/framework/workflows-sdk"5import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"6import {7 createProductStep,8 getProductStep,9 createPricesStep10} from "./steps"11 12interface WorkflowInput {13 title: string14}15 16const myWorkflow = createWorkflow(17 "my-workflow",18 (input: WorkflowInput) => {19 // Everything here will be executed and resolved later20 // during the execution. Including the data access.21 22 const product = createProductStep(input)23 const prices = createPricesStep(product)24 return new WorkflowResponse(getProductStep(product.id))25 }26)27 28export async function GET(29 req: MedusaRequest,30 res: MedusaResponse31) {32 const { result: product } = await myWorkflow(req.scope)33 .run({34 input: {35 title: "Shirt"36 }37 })38 39 res.json({40 product41 })42}
Type Parameters#
Loading...
Parameters#
Loading...
Returns#
Loading...
Was this page helpful?