> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# CreateFulfillment

# Package: orders

# Namespace: Fulfillments

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/order-fulfillments/create-fulfillment.md

## Permission Scopes:
Manage Orders: SCOPE.DC-STORES.MANAGE-ORDERS

## Introduction

Creates an order fulfillment.

A line item's quantity can be split across multiple fulfillments. When `lineItems[i].quantity` isn't passed, it defaults to the line item's remaining unfulfilled quantity.

> **Notes:**
> + Fulfillments can only be created for orders with `status: "APPROVED"`.
> + When passing `trackingInfo`, both `trackingNumber` and `shippingProvider` are required.
> + Don't pass `fulfillment.id`. It's assigned automatically and passing it results in an error.
> + A shipping notification email may be sent to the buyer when the fulfillment is created, depending on the site's email settings.
> + The order's `fulfillmentStatus` is recalculated asynchronously after the call.

To create fulfillments for multiple orders in a single call, call [Bulk Create Fulfillments](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/order-fulfillments/bulk-create-fulfillments.md).

---

## REST API

### Schema

```
 Method: createFulfillment
 Description: Creates an order fulfillment.  A line item's quantity can be split across multiple fulfillments. When `lineItems[i].quantity` isn't passed, it defaults to the line item's remaining unfulfilled quantity.  > **Notes:** > + Fulfillments can only be created for orders with `status: "APPROVED"`. > + When passing `trackingInfo`, both `trackingNumber` and `shippingProvider` are required. > + Don't pass `fulfillment.id`. It's assigned automatically and passing it results in an error. > + A shipping notification email may be sent to the buyer when the fulfillment is created, depending on the site's email settings. > + The order's `fulfillmentStatus` is recalculated asynchronously after the call.  To create fulfillments for multiple orders in a single call, call [Bulk Create Fulfillments](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/order-fulfillments/bulk-create-fulfillments.md).
 URL: https://www.wixapis.com/ecom/v1/fulfillments/orders/{orderId}/create-fulfillment
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  fulfillment, fulfillment.lineItems, fulfillment.lineItems.id
 Method parameters: 
   param name: fulfillment | type: Fulfillment | description: A fulfillment represents the shipment or delivery of some or all of an order's line items. | required: true 
    - ONE-OF: - required: true
     - name: trackingInfo | type: FulfillmentTrackingInfo | description: Tracking info.  
        - name: trackingNumber | type: string | description: Shipping/delivery tracking number.  | validation: minLength 1, maxLength 100
        - name: shippingProvider | type: string | description: Shipping provider name. Specify a predefined provider to have `trackingLink` generated automatically, or any other name for a custom provider.  Predefined providers: + `"fedex"`: FedEx. + `"ups"`: UPS. + `"usps"`: United States Postal Service. + `"dhl"`: DHL. + `"canadaPost"`: Canada Post. + `"hermes"`: Hermes.  For a custom provider, specify `trackingLink` yourself. It isn't generated.  | validation: minLength 1, maxLength 100
        - name: trackingLink | type: string | description: URL where customers can track the shipment.  When you don't specify `trackingLink` and `shippingProvider` is a predefined provider, the URL is generated from `trackingNumber` in the carrier's tracking URL format. For a custom provider, specify the URL of the carrier's tracking page.  | validation: minLength 1, maxLength 2048, format WEB_URL
     - name: customInfo | type: CustomFulfillmentInfo | description: Custom fulfillment info.  
        - name: fieldsData | type: object | description: Custom fulfillment info in key:value form.  | validation: minItems 0, maxItems 100, format map
        - name: lineItems | type: array<FulfillmentLineItem> | description: Line items being fulfilled. | required: true | validation: minItems 0, maxItems 300
           - name: id | type: string | description: Line item GUID (mirrors the GUID of the order line item).  | validation: format GUID
           - name: quantity | type: integer | description: Line item quantity.  If the order doesn't have enough unfulfilled units of this line item, the fulfillment isn't created and an error is returned.  Default: When creating a fulfillment, the line item's remaining unfulfilled quantity.  | validation: minimum 1, maximum 100000, format int32
        - name: status | type: string | description: The current status of the fulfillment process.  Supported values (case-sensitive, any other value is rejected): + `"Pending"` - Initial state when fulfillment is created but processing hasn't started. + `"Accepted"` - Order has been received and validated for fulfillment. + `"Ready"` - Items have been picked and packed, ready for shipping. + `"In_Delivery"` - Items have been handed over to the shipping carrier. + `"Fulfilled"` - Delivery has been completed successfully.  The status typically progresses from `Pending` to `Accepted`, `Ready`, `In_Delivery`, and finally `Fulfilled`. Update the status manually or automatically depending on your fulfillment workflow.  This field is informational. The order's `fulfillmentStatus` is primarily derived from the fulfilled line item quantities, not from this field.  | validation: minLength 1, maxLength 100
        - name: completed | type: boolean | description: Whether the fulfillment is complete.  When `false`, the fulfillment's line items don't count as fulfilled when the order's `fulfillmentStatus` is calculated. When not set, they count as fulfilled.  Line items can't be updated in a fulfillment where `completed` is `true`.  
 Return type: CreateFulfillmentResponse
  - name: orderWithFulfillments | type: OrderWithFulfillments | description: Order GUID and all of the order's fulfillments, including the created fulfillment.  
     - name: orderId | type: string | description: Order GUID.  | validation: minLength 1, maxLength 100
     - name: fulfillments | type: array<Fulfillment> | description: Fulfillments associated with the order.  
        - ONE-OF: 
           - name: trackingInfo | type: FulfillmentTrackingInfo | description: Tracking info.  
              - name: trackingNumber | type: string | description: Shipping/delivery tracking number.  | validation: minLength 1, maxLength 100
              - name: shippingProvider | type: string | description: Shipping provider name. Specify a predefined provider to have `trackingLink` generated automatically, or any other name for a custom provider.  Predefined providers: + `"fedex"`: FedEx. + `"ups"`: UPS. + `"usps"`: United States Postal Service. + `"dhl"`: DHL. + `"canadaPost"`: Canada Post. + `"hermes"`: Hermes.  For a custom provider, specify `trackingLink` yourself. It isn't generated.  | validation: minLength 1, maxLength 100
              - name: trackingLink | type: string | description: URL where customers can track the shipment.  When you don't specify `trackingLink` and `shippingProvider` is a predefined provider, the URL is generated from `trackingNumber` in the carrier's tracking URL format. For a custom provider, specify the URL of the carrier's tracking page.  | validation: minLength 1, maxLength 2048, format WEB_URL
           - name: customInfo | type: CustomFulfillmentInfo | description: Custom fulfillment info.  
              - name: fieldsData | type: object | description: Custom fulfillment info in key:value form.  | validation: minItems 0, maxItems 100, format map
        - name: id | type: string | description: Fulfillment GUID.  | read-only: true | validation: format GUID
        - name: createdDate | type: string | description: Date and time the fulfillment was created.  | read-only: true | validation: format date-time
        - name: lineItems | type: array<FulfillmentLineItem> | description: Line items being fulfilled.  | validation: minItems 0, maxItems 300
           - name: id | type: string | description: Line item GUID (mirrors the GUID of the order line item).  | validation: format GUID
           - name: quantity | type: integer | description: Line item quantity.  If the order doesn't have enough unfulfilled units of this line item, the fulfillment isn't created and an error is returned.  Default: When creating a fulfillment, the line item's remaining unfulfilled quantity.  | validation: minimum 1, maximum 100000, format int32
        - name: status | type: string | description: The current status of the fulfillment process.  Supported values (case-sensitive, any other value is rejected): + `"Pending"` - Initial state when fulfillment is created but processing hasn't started. + `"Accepted"` - Order has been received and validated for fulfillment. + `"Ready"` - Items have been picked and packed, ready for shipping. + `"In_Delivery"` - Items have been handed over to the shipping carrier. + `"Fulfilled"` - Delivery has been completed successfully.  The status typically progresses from `Pending` to `Accepted`, `Ready`, `In_Delivery`, and finally `Fulfilled`. Update the status manually or automatically depending on your fulfillment workflow.  This field is informational. The order's `fulfillmentStatus` is primarily derived from the fulfilled line item quantities, not from this field.  | validation: minLength 1, maxLength 100
        - name: completed | type: boolean | description: Whether the fulfillment is complete.  When `false`, the fulfillment's line items don't count as fulfilled when the order's `fulfillmentStatus` is calculated. When not set, they count as fulfilled.  Line items can't be updated in a fulfillment where `completed` is `true`.  
  - name: fulfillmentId | type: string | description: GUID of the created fulfillment.  

 Possible Errors:
   HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: TRACKING_NUMBER_ALREADY_EXISTS | Description: There is already a fulfillment for this order with the same tracking number and shipping provider.


```

### Examples

### Create Fulfillment
Creates a fulfillment with a predefined shipping provider. The response includes a generated `trackingLink`.

```curl
curl -X POST \
  'https://www.wixapis.com/ecom/v1/fulfillments/orders/58c9a790-27b7-463f-a865-c7cb494f7c29/create-fulfillment' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: <AUTH>' \
  -d '{
    "fulfillment": {
      "lineItems": [
        {
          "id": "00000000-0000-0000-0000-000000000001",
          "quantity": 1
        }
      ],
      "trackingInfo": {
        "trackingNumber": "12345",
        "shippingProvider": "fedex"
      }
    }
  }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.ecom.orderFulfillments.createFulfillment(orderId, fulfillment)
 Description: Creates an order fulfillment.  A line item's quantity can be split across multiple fulfillments. When `lineItems[i].quantity` isn't passed, it defaults to the line item's remaining unfulfilled quantity.  > **Notes:** > + Fulfillments can only be created for orders with `status: "APPROVED"`. > + When passing `trackingInfo`, both `trackingNumber` and `shippingProvider` are required. > + Don't pass `fulfillment.id`. It's assigned automatically and passing it results in an error. > + A shipping notification email may be sent to the buyer when the fulfillment is created, depending on the site's email settings. > + The order's `fulfillmentStatus` is recalculated asynchronously after the call.  To create fulfillments for multiple orders in a single call, call [Bulk Create Fulfillments](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/order-fulfillments/bulk-create-fulfillments.md).
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  orderId, fulfillment, fulfillment.lineItems, fulfillment.lineItems._id
 Method parameters: 
   param name: orderId | type: string | description: Order GUID. | required: true 
   param name: fulfillment | type: Fulfillment | description: A fulfillment represents the shipment or delivery of some or all of an order's line items. | required: true 
    - ONE-OF: - required: true
     - name: trackingInfo | type: FulfillmentTrackingInfo | description: Tracking info.  
        - name: trackingNumber | type: string | description: Shipping/delivery tracking number.  | validation: minLength 1, maxLength 100
        - name: shippingProvider | type: string | description: Shipping provider name. Specify a predefined provider to have `trackingLink` generated automatically, or any other name for a custom provider.  Predefined providers: + `"fedex"`: FedEx. + `"ups"`: UPS. + `"usps"`: United States Postal Service. + `"dhl"`: DHL. + `"canadaPost"`: Canada Post. + `"hermes"`: Hermes.  For a custom provider, specify `trackingLink` yourself. It isn't generated.  | validation: minLength 1, maxLength 100
        - name: trackingLink | type: string | description: URL where customers can track the shipment.  When you don't specify `trackingLink` and `shippingProvider` is a predefined provider, the URL is generated from `trackingNumber` in the carrier's tracking URL format. For a custom provider, specify the URL of the carrier's tracking page.  | validation: minLength 1, maxLength 2048, format WEB_URL
     - name: customInfo | type: CustomFulfillmentInfo | description: Custom fulfillment info.  
        - name: fieldsData | type: object | description: Custom fulfillment info in key:value form.  | validation: minItems 0, maxItems 100, format map
        - name: lineItems | type: array<FulfillmentLineItem> | description: Line items being fulfilled. | required: true | validation: minItems 0, maxItems 300
           - name: _id | type: string | description: Line item GUID (mirrors the GUID of the order line item).  | validation: format GUID
           - name: quantity | type: integer | description: Line item quantity.  If the order doesn't have enough unfulfilled units of this line item, the fulfillment isn't created and an error is returned.  Default: When creating a fulfillment, the line item's remaining unfulfilled quantity.  | validation: minimum 1, maximum 100000, format int32
        - name: status | type: string | description: The current status of the fulfillment process.  Supported values (case-sensitive, any other value is rejected): + `"Pending"` - Initial state when fulfillment is created but processing hasn't started. + `"Accepted"` - Order has been received and validated for fulfillment. + `"Ready"` - Items have been picked and packed, ready for shipping. + `"In_Delivery"` - Items have been handed over to the shipping carrier. + `"Fulfilled"` - Delivery has been completed successfully.  The status typically progresses from `Pending` to `Accepted`, `Ready`, `In_Delivery`, and finally `Fulfilled`. Update the status manually or automatically depending on your fulfillment workflow.  This field is informational. The order's `fulfillmentStatus` is primarily derived from the fulfilled line item quantities, not from this field.  | validation: minLength 1, maxLength 100
        - name: completed | type: boolean | description: Whether the fulfillment is complete.  When `false`, the fulfillment's line items don't count as fulfilled when the order's `fulfillmentStatus` is calculated. When not set, they count as fulfilled.  Line items can't be updated in a fulfillment where `completed` is `true`.  
 Return type: PROMISE<CreateFulfillmentResponse>
  - name: orderWithFulfillments | type: OrderWithFulfillments | description: Order GUID and all of the order's fulfillments, including the created fulfillment.  
     - name: orderId | type: string | description: Order GUID.  | validation: minLength 1, maxLength 100
     - name: fulfillments | type: array<Fulfillment> | description: Fulfillments associated with the order.  
        - ONE-OF: 
           - name: trackingInfo | type: FulfillmentTrackingInfo | description: Tracking info.  
              - name: trackingNumber | type: string | description: Shipping/delivery tracking number.  | validation: minLength 1, maxLength 100
              - name: shippingProvider | type: string | description: Shipping provider name. Specify a predefined provider to have `trackingLink` generated automatically, or any other name for a custom provider.  Predefined providers: + `"fedex"`: FedEx. + `"ups"`: UPS. + `"usps"`: United States Postal Service. + `"dhl"`: DHL. + `"canadaPost"`: Canada Post. + `"hermes"`: Hermes.  For a custom provider, specify `trackingLink` yourself. It isn't generated.  | validation: minLength 1, maxLength 100
              - name: trackingLink | type: string | description: URL where customers can track the shipment.  When you don't specify `trackingLink` and `shippingProvider` is a predefined provider, the URL is generated from `trackingNumber` in the carrier's tracking URL format. For a custom provider, specify the URL of the carrier's tracking page.  | validation: minLength 1, maxLength 2048, format WEB_URL
           - name: customInfo | type: CustomFulfillmentInfo | description: Custom fulfillment info.  
              - name: fieldsData | type: object | description: Custom fulfillment info in key:value form.  | validation: minItems 0, maxItems 100, format map
        - name: _id | type: string | description: Fulfillment GUID.  | read-only: true | validation: format GUID
        - name: _createdDate | type: Date | description: Date and time the fulfillment was created.  | read-only: true 
        - name: lineItems | type: array<FulfillmentLineItem> | description: Line items being fulfilled.  | validation: minItems 0, maxItems 300
           - name: _id | type: string | description: Line item GUID (mirrors the GUID of the order line item).  | validation: format GUID
           - name: quantity | type: integer | description: Line item quantity.  If the order doesn't have enough unfulfilled units of this line item, the fulfillment isn't created and an error is returned.  Default: When creating a fulfillment, the line item's remaining unfulfilled quantity.  | validation: minimum 1, maximum 100000, format int32
        - name: status | type: string | description: The current status of the fulfillment process.  Supported values (case-sensitive, any other value is rejected): + `"Pending"` - Initial state when fulfillment is created but processing hasn't started. + `"Accepted"` - Order has been received and validated for fulfillment. + `"Ready"` - Items have been picked and packed, ready for shipping. + `"In_Delivery"` - Items have been handed over to the shipping carrier. + `"Fulfilled"` - Delivery has been completed successfully.  The status typically progresses from `Pending` to `Accepted`, `Ready`, `In_Delivery`, and finally `Fulfilled`. Update the status manually or automatically depending on your fulfillment workflow.  This field is informational. The order's `fulfillmentStatus` is primarily derived from the fulfilled line item quantities, not from this field.  | validation: minLength 1, maxLength 100
        - name: completed | type: boolean | description: Whether the fulfillment is complete.  When `false`, the fulfillment's line items don't count as fulfilled when the order's `fulfillmentStatus` is calculated. When not set, they count as fulfilled.  Line items can't be updated in a fulfillment where `completed` is `true`.  
  - name: fulfillmentId | type: string | description: GUID of the created fulfillment.  

 Possible Errors:
   HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: TRACKING_NUMBER_ALREADY_EXISTS | Description: There is already a fulfillment for this order with the same tracking number and shipping provider.


```

### Examples

### Create a fulfillment (with elevated permissions)
When you specify a predefined `shippingProvider`, the response includes a generated `trackingLink`.

```javascript
import { orderFulfillments } from '@wix/ecom';
import { auth } from '@wix/essentials';

/* Sample orderId value: 'e613320a-8e8f-4f8f-9d87-b5edc9f99788';

* Sample fulfillment value:
* {
*   lineItems: [{
*     _id: '00000000-0000-0000-0000-000000000001',
*     quantity: 1
*   }],
*   trackingInfo: {
*     trackingNumber: '12345',
*     shippingProvider: 'dhl'
*   }
* };
*/

const elevatedCreateFulfillment = auth.elevate(orderFulfillments.createFulfillment);

export async function myCreateFulfillmentFunction(orderId, fulfillment) {
  try {
    const newFulfillment = await elevatedCreateFulfillment(orderId, fulfillment);

    const fulfillmentId = newFulfillment.fulfillmentId;
    const newOrderFulfillments = newFulfillment.orderWithFulfillments.fulfillments;
    const createdFulfillment = newOrderFulfillments.find((fulfillment) => fulfillment._id === fulfillmentId);
    const trackingLink = createdFulfillment.trackingInfo.trackingLink;
    console.log('Success! Created new fulfillment:', newFulfillment);

    return newFulfillment;
  } catch (error) {
    console.error(error);
    // Handle the error
  }

}

/* Promise resolves to:
 *
 * {
 *   "orderWithFulfillments": {
 *     "orderId": "e613320a-8e8f-4f8f-9d87-b5edc9f99788",
 *     "fulfillments": [
 *       {
 *         "_id": "91357295-a95c-4973-b210-281640f3e795",
 *         "_createdDate": "2023-03-06T15:23:29.967Z",
 *         "lineItems": [
 *           {
 *             "_id": "00000000-0000-0000-0000-000000000001",
 *             "quantity": 1
 *           }
 *         ],
 *         "trackingInfo": {
 *           "trackingNumber": "12345",
 *           "shippingProvider": "dhl",
 *           "trackingLink": "https://www.logistics.dhl/global-en/home/tracking.html?tracking-id=12345"
 *         }
 *       }
 *     ]
 *   },
 *   "fulfillmentId": "91357295-a95c-4973-b210-281640f3e795"
 * }
 *
 */
```

### Create a fulfillment
When you specify a predefined `shippingProvider`, the response includes a generated `trackingLink`.

```javascript
import { orderFulfillments } from '@wix/ecom';

/* Sample orderId value: 'e613320a-8e8f-4f8f-9d87-b5edc9f99788';

 * Sample fulfillment value:
 * {
 *   lineItems: [{
 *     _id: '00000000-0000-0000-0000-000000000001',
 *     quantity: 1
 *   }],
 *   trackingInfo: {
 *     trackingNumber: '12345',
 *     shippingProvider: 'dhl'
 *   }
 * };
 */

export async function myCreateFulfillmentFunction(orderId, fulfillment) {
  try {
    const newFulfillment = await orderFulfillments.createFulfillment(orderId, fulfillment);

    const fulfillmentId = newFulfillment.fulfillmentId;
    const newOrderFulfillments = newFulfillment.orderWithFulfillments.fulfillments;
    const createdFulfillment = newOrderFulfillments.find((fulfillment) => fulfillment._id === fulfillmentId);
    const trackingLink = createdFulfillment.trackingInfo.trackingLink;
    console.log('Success! Created new fulfillment:', newFulfillment);

    return newFulfillment;
  } catch (error) {
    console.error(error);
    // Handle the error
  }

}

/* Promise resolves to:
 *
 * {
 *   "orderWithFulfillments": {
 *     "orderId": "e613320a-8e8f-4f8f-9d87-b5edc9f99788",
 *     "fulfillments": [
 *       {
 *         "_id": "91357295-a95c-4973-b210-281640f3e795",
 *         "_createdDate": "2023-03-06T15:23:29.967Z",
 *         "lineItems": [
 *           {
 *             "_id": "00000000-0000-0000-0000-000000000001",
 *             "quantity": 1
 *           }
 *         ],
 *         "trackingInfo": {
 *           "trackingNumber": "12345",
 *           "shippingProvider": "dhl",
 *           "trackingLink": "https://www.logistics.dhl/global-en/home/tracking.html?tracking-id=12345"
 *         }
 *       }
 *     ]
 *   },
 *   "fulfillmentId": "91357295-a95c-4973-b210-281640f3e795"
 * }
 *
 */
```

### createFulfillment (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { orderFulfillments } from '@wix/ecom';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { orderFulfillments },
  // Include the auth strategy and host as relevant
});


async function createFulfillment(orderId,fulfillment) {
  const response = await myWixClient.orderFulfillments.createFulfillment(orderId,fulfillment);
};
```

---