createOrderFulfillmentWorkflow - Medusa Core Workflows Reference

This documentation provides a reference to the createOrderFulfillmentWorkflow. It belongs to the @medusajs/medusa/core-flows package.

This workflow creates a fulfillment for an order. It's used by the Create Order Fulfillment Admin API Route.

This workflow has a hook that allows you to perform custom actions on the created fulfillment. For example, you can pass under additional_data custom data that allows you to create custom data models linked to the fulfillment.

You can also use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around creating a fulfillment.

Source Code

Examples#

Steps#

Input#

CreateOrderFulfillmentWorkflowInputCreateOrderFulfillmentWorkflowInput
The details of the fulfillment to create, along with custom data that's passed to the workflow's hooks.
order_idstring
The ID of the order to create the fulfillment for.
A list of items to be fulfilled.
items_listOrderLineItemDTO[]Optional
The list of items in the order. If not provided, the order's items are used.
created_bystringOptional
The ID of the user who created the fulfillment.
The labels to associate with the order.
no_notificationbooleanOptional
Whether the notify the customer about the fulfillment.
location_idnull | stringOptional
The ID of the stock location to fulfill items from. If not provided, the workflow uses the ID of the location associated with the shipping option used by the order's shipping method.
metadatanull | Record<string, any>Optional
Custom k-value pairs related to the fulfillment.
requires_shippingbooleanOptional
Whether the fulfillment should be shipped.
additional_dataRecord<string, unknown>Optional
Additional data that can be passed through the additional_data property in HTTP requests. Learn more in this documentation.

Output#

FulfillmentDTOFulfillmentDTO
The fulfillment details.
idstring
The ID of the fulfillment.
location_idstring
The associated location's ID.
packed_atnull | Date
The date the fulfillment was packed.
shipped_atnull | Date
The date the fulfillment was shipped.
delivered_atnull | Date
The date the fulfillment was delivered.
canceled_atnull | Date
The date the fulfillment was canceled.
datanull | Record<string, unknown>
The data necessary for the fulfillment provider to process the fulfillment.
provider_idstring
The associated fulfillment provider's ID.
shipping_option_idnull | string
The associated shipping option's ID.
metadatanull | Record<string, unknown>
Holds custom data in key-value pairs.
shipping_optionnull | ShippingOptionDTO
The associated shipping option.
requires_shippingboolean
Flag to indidcate whether shipping is required
The associated fulfillment provider.
delivery_addressFulfillmentAddressDTO
The associated fulfillment address used for delivery.
The items of the fulfillment.
The labels of the fulfillment.
created_atDate
The creation date of the fulfillment.
updated_atDate
The update date of the fulfillment.
deleted_atnull | Date
The deletion date of the fulfillment.
marked_shipped_bynull | stringOptional
The id of the user that marked fulfillment as shipped
created_bynull | stringOptional
The id of the user that created the fulfillment

Hooks#

Hooks allow you to inject custom functionalities into the workflow. You'll receive data from the workflow, as well as additional data sent through an HTTP request.

Learn more about Hooks and Additional Data.

fulfillmentCreated#

This hook is executed after the fulfillment is created. You can consume this hook to perform custom actions on the created fulfillment.

Example

Code
1import { createOrderFulfillmentWorkflow } from "@medusajs/medusa/core-flows"2
3createOrderFulfillmentWorkflow.hooks.fulfillmentCreated(4  (async ({ fulfillment, additional_data }, { container }) => {5    //TODO6  })7)

Input

Handlers consuming this hook accept the following input.

inputobject
The input data for the hook.
fulfillmentFulfillmentDTO
The fulfillment details.
additional_dataRecord<string, unknown> | undefined
Additional data that can be passed through the additional\_data property in HTTP requests. Learn more in this documentation.
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break