Search.../

createFulfillment( )

Creates an order fulfillment.

Description

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

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function createFulfillment(orderId: string, fulfillment: Fulfillment): Promise<CreateFulfillmentResponse>

createFulfillment Parameters

NAME
TYPE
DESCRIPTION
orderId
string

Order ID.

fulfillment
Fulfillment

Fulfillment info.

Returns

Return Type:

Promise<
CreateFulfillmentResponse
>
NAME
TYPE
DESCRIPTION
fulfillmentId
string

ID of created fulfillment.

orderWithFulfillments
OrderWithFulfillments

Order ID and the orders' fulfillments.

Was this helpful?

Create a fulfillment

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

Copy Code
1import { orderFulfillments } from 'wix-ecom-backend';
2
3/* Sample orderId value: 'e613320a-8e8f-4f8f-9d87-b5edc9f99788';
4
5 * Sample fulfillment value:
6 * {
7 * lineItems: [{
8 * id: '00000000-0000-0000-0000-000000000001',
9 * quantity: 1
10 * }],
11 * trackingInfo: {
12 * trackingNumber: '12345',
13 * shippingProvider: 'dhl'
14 * }
15 * };
16 */
17
18export async function myCreateFulfillmentFunction(orderId, fulfillment) {
19 try {
20 const newFulfillment = await orderFulfillments.createFulfillment(orderId, fulfillment);
21
22 const fulfillmentId = newFulfillment.fulfillmentId;
23 const newOrderFulfillments = newFulfillment.orderWithFulfillments.fulfillments;
24 const trackingLink = orderFulfillments[0].trackingInfo.trackingLink;
25 console.log('Success! Created new fulfillment:', newFulfillment);
26
27 return newFulfillment;
28 } catch (error) {
29 console.error(error);
30 // Handle the error
31 }
32
33}
34
35/* Promise resolves to:
36 *
37 * {
38 * "orderWithFulfillments": {
39 * "orderId": "e613320a-8e8f-4f8f-9d87-b5edc9f99788",
40 * "fulfillments": [
41 * {
42 * "_id": "91357295-a95c-4973-b210-281640f3e795",
43 * "_createdDate": "2023-03-06T15:23:29.967Z",
44 * "lineItems": [
45 * {
46 * "_id": "00000000-0000-0000-0000-000000000001",
47 * "quantity": 1
48 * }
49 * ],
50 * "trackingInfo": {
51 * "trackingNumber": "12345",
52 * "shippingProvider": "dhl",
53 * "trackingLink": "https://www.logistics.dhl/global-en/home/tracking.html?tracking-id=12345"
54 * }
55 * }
56 * ]
57 * },
58 * "fulfillmentId": "91357295-a95c-4973-b210-281640f3e795"
59 * }
60 *
61 */