Skip to main content
Skip to main content

ReturnWorkflow

ReturnWorkflow: <TDataOverride, TResultOverride>(container?: MedusaContainer | { __joinerConfig: [ModuleJoinerConfig](/references/medusa/types/medusa.ModuleJoinerConfig) ; __definition: [ModuleDefinition](/references/medusa/types/medusa.ModuleDefinition) }[]) => Omit<LocalWorkflow, "run" | "registerStepSuccess" | "registerStepFailure"> & ExportedWorkflow<TData, TResult, TDataOverride, TResultOverride> & THooks & object & object

An exported workflow, which is the type of a workflow constructed by the createWorkflow function. The exported workflow can be invoked to create an executable workflow, optionally within a specified container. So, to execute the workflow, you must invoke the exported workflow, then run the run method of the exported workflow.

Example

To execute a workflow:

myWorkflow()
.run({
input: {
name: "John"
}
})
.then(({ result }) => {
console.log(result)
})

To specify the container of the workflow, you can pass it as an argument to the call of the exported workflow. This is necessary when executing the workflow within a Medusa resource such as an API Route or a Subscriber.

For example:

import type {
MedusaRequest,
MedusaResponse
} from "@medusajs/medusa";
import myWorkflow from "../../../workflows/hello-world";

export async function GET(
req: MedusaRequest,
res: MedusaResponse
) {
const { result } = await myWorkflow(req.scope)
.run({
input: {
name: req.query.name as string
}
})

res.send(result)
}

Type Parameters

TDataobjectRequired
TResultobjectRequired
THooksRecord<string, Function>Required
Was this section helpful?