createFulfillment( )


Creates an order fulfillment.

The createFulfillment() function returns a Promise that resolves when the fulfillment is created.

Authentication

This function requires elevated permissions and runs only on the backend and on dashboard pages.

Permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Manage eCommerce - all permissions
Manage Orders
Learn more about app permissions.
Method Declaration
Copy
function createFulfillment(
  orderId: string,
  fulfillment: Fulfillment,
): Promise<CreateFulfillmentResponse>;
Method Parameters
orderIdstringRequired

Order ID.


fulfillmentFulfillmentRequired

Fulfillment info.

Returns
Return Type:Promise<CreateFulfillmentResponse>

By passing a supported shippingProvider, the trackingLink field is auto-populated in the response

JavaScript
import { orderFulfillments } from "wix-ecom-backend"; /* 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 trackingLink = orderFulfillments[0].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" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?