1 export const metadata = {
2 title: `Item Fulfillment Concepts`,
3 }
4
5 # {metadata.title}
6
7 In this document, you’ll learn about the concepts related to item fulfillment.
8
9 ## Fulfillment Data Model
10
11 A fulfillment is the shipping and delivery of one or more items to the customer. It’s represented by the [Fulfillment data model](/references/fulfillment/models/Fulfillment).
12
13 A fulfillment can be created to fulfill orders, [returns](../../order/return/), [exchanges](../../order/exchange/page.mdx), and [claims](../../order/claim/page.mdx).
14
15 ---
16
17 ## Fulfillment Processing by a Fulfillment Provider
18
19 A fulfillment is associated with a [fulfillment provider](../fulfillment-provider/page.mdx) that handles all its processing, such as creating a shipment for the fulfillment’s items.
20
21 The fulfillment is also associated with a [shipping option](../shipping-option/page.mdx) of that provider, which determines how the item is shipped.
22
23 ![A diagram showcasing the relation between a fulfillment, fulfillment provider, and shipping option](https://res.cloudinary.com/dza7lstvk/image/upload/v1712331947/Medusa%20Resources/fulfillment-shipping-option_jk9ndp.jpg)
24
25 ---
26
27 ## data Property of Fulfillment Data Model
28
29 The `Fulfillment` data model has a `data` property that holds any necessary data for the third-party fulfillment provider to process the fulfillment.
30
31 For example, the `data` property can hold the ID of the fulfillment in the third-party provider. The associated fulfillment provider then uses it whenever it retrieves the fulfillment's details.
32
33 ---
34
35 ## Pass Additional Data to the Fulfillment Provider
36
37 <Note>
38
39 This feature is available since Medusa [v2.19.0](https://github.com/medusajs/medusa/releases/tag/v2.19.0).
40
41 </Note>
42
43 When creating a fulfillment through the [Create Fulfillment API route](!api!/admin/orders/create-fulfillment), you can pass an `additional_data` field in the request body. Unlike the `data` field, `additional_data` is not persisted on the fulfillment record; it is only forwarded as-is to the Fulfillment Module Provider's `createFulfillment` method.
44
45 This lets you send custom key-value pairs to the provider at creation time without storing them on the fulfillment. For example, you can pass a carrier-specific instruction that the provider reads when it talks to the third-party service:
46
47 ```json title="Request body"
48 {
49 "location_id": "loc_123",
50 "items": [...],
51 "additional_data": {
52 "carrier_instruction": "leave_at_door"
53 }
54 }
55 ```
56
57 In the Fulfillment Module Provider's `createFulfillment` method, the fifth argument receives this object:
58
59 ```ts title="src/modules/my-fulfillment/service.ts"
60 class MyFulfillmentProviderService
61 extends AbstractFulfillmentProviderService {
62 // ...
63
64 async createFulfillment(
65 data: Record<string, unknown>,
66 items: object[],
67 order: object | undefined,
68 fulfillment: Record<string, unknown>,
69 additionalData?: Record<string, unknown>
70 ) {
71 const instruction = additionalData?.carrier_instruction
72 // use instruction when calling the third-party service
73 }
74 }
75 ```
76
77 ---
78
79 ## Override Delivery Address Per Fulfillment
80
81 <Note>
82
83 This feature is available since Medusa [v2.19.0](https://github.com/medusajs/medusa/releases/tag/v2.19.0).
84
85 </Note>
86
87 By default, when creating a fulfillment for an order, Medusa uses the order's shipping address as the delivery address sent to the Fulfillment Module Provider.
88
89 You can override this on a per-fulfillment basis by passing a `delivery_address` field in the [Create Fulfillment API route](!api!/admin/orders/create-fulfillment) request body. The provided address is merged over the order's shipping address, so you only need to supply the fields you want to change:
90
91 ```json title="Request body"
92 {
93 "location_id": "loc_123",
94 "items": [...],
95 "delivery_address": {
96 "first_name": "Jane",
97 "last_name": "Doe"
98 }
99 }
100 ```
101
102 The merged address is forwarded to the Fulfillment Module Provider but the order's shipping address is not mutated.
103
104 ---
105
106 ## Fulfillment Items
107
108 A fulfillment is used to fulfill one or more items. Each item is represented by the [FulfillmentItem data model](/references/fulfillment/models/FulfillmentItem).
109
110 The fulfillment item holds details relevant to fulfilling the item, such as barcode, SKU, and quantity to fulfill.
111
112 ![A diagram showcasing the relation between fulfillment and fulfillment items.](https://res.cloudinary.com/dza7lstvk/image/upload/v1712332114/Medusa%20Resources/fulfillment-item_etzxb0.jpg)
113
114 ---
115
116 ## Fulfillment Label
117
118 Once a shipment is created for the fulfillment, you can store its tracking number, URL, or other related details as a label, represented by the [FulfillmentLabel data model](/references/fulfillment/models/FulfillmentLabel).
119
120 ### Accessing Tracking Information
121
122 To access tracking information for a fulfillment, you must retrieve the related labels. For example, to retrieve the tracking data with [Query](!docs!/learn/fundamentals/query):
123
124 ```ts
125 const { data: fulfillment } = query.graph({
126 entity: "fulfillment",
127 fields: [
128 "labels.tracking_number",
129 "labels.tracking_url",
130 "labels.label_url",
131 ],
132 filters: {
133 id: "fulfillment_123",
134 },
135 })
136
137 fulfillment.labels.forEach((label) => {
138 console.log("Tracking Number:", label.tracking_number)
139 console.log("Tracking URL:", label.tracking_url)
140 console.log("Label URL:", label.label_url)
141 })
142 ```
143
144 ---
145
146 ## Fulfillment Status
147
148 The [Fulfillment data model](/references/fulfillment/models/Fulfillment) has three properties to determine the current status of the fulfillment:
149
150 - `packed_at`: The date the fulfillment was packed. If set, the fulfillment has been packed.
151 - `shipped_at`: The date the fulfillment was shipped. If set, the fulfillment has been shipped.
152 - `delivered_at`: The date the fulfillment was delivered. If set, the fulfillment has been delivered.