Fulfillment Module

In this section of the documentation, you will find resources to learn more about the Fulfillment Module and how to use it in your application.

Medusa has fulfillment related features available out-of-the-box through the Fulfillment Module. A module is a standalone package that provides features for a single domain. Each of Medusa's commerce features are placed in commerce modules, such as this Fulfillment Module.

NoteLearn more about why modules are isolated in this documentation.

Fulfillment Features#


How to Use the Fulfillment Module#

In your Medusa application, you build flows around commerce modules. A flow is built as a Workflow, which is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.

You can build custom workflows and steps. You can also re-use Medusa's workflows and steps, which are provided by the @medusajs/medusa/core-flows package.

For example:

src/workflows/create-fulfillment.ts
1import { 2  createWorkflow, 3  WorkflowResponse,4  createStep,5  StepResponse,6} from "@medusajs/framework/workflows-sdk"7import { Modules } from "@medusajs/framework/utils"8
9const createFulfillmentStep = createStep(10  "create-fulfillment",11  async ({}, { container }) => {12    const fulfillmentModuleService = container.resolve(Modules.FULFILLMENT)13
14    const fulfillment = await fulfillmentModuleService.createFulfillment({15      location_id: "loc_123",16      provider_id: "webshipper",17      delivery_address: {18        country_code: "us",19        city: "Strongsville",20        address_1: "18290 Royalton Rd",21      },22      items: [23        {24          title: "Shirt",25          sku: "SHIRT",26          quantity: 1,27          barcode: "123456",28        },29      ],30      labels: [],31      order: {},32    })33
34    return new StepResponse({ fulfillment }, fulfillment.id)35  },36  async (fulfillmentId, { container }) => {37    if (!fulfillmentId) {38      return39    }40    const fulfillmentModuleService = container.resolve(Modules.FULFILLMENT)41
42    await fulfillmentModuleService.deleteFulfillment(fulfillmentId)43  }44)45
46export const createFulfillmentWorkflow = createWorkflow(47  "create-fulfillment",48  () => {49    const { fulfillment } = createFulfillmentStep()50
51    return new WorkflowResponse({52      fulfillment,53    })54  }55)

You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:

Learn more about workflows in this documentation.


Configure Fulfillment Module#

The Fulfillment Module accepts options for further configurations. Refer to this documentation for details on the module's options.


Was this page helpful?
Edit this page