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 (dashboard page code)

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 */
Create a fulfillment (export from backend code)

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

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