Search.../

bulkCreateFulfillments( )

Creates multiple fulfillments for one or more orders.

Description

The bulkCreateFulfillments() function returns a Promise that resolves when the fulfillments are created.

Admin Method

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

Syntax

function bulkCreateFulfillments(ordersWithFulfillments: Array<BulkCreateOrderWithFulfillments>): Promise<BulkCreateFulfillmentResponse>

bulkCreateFulfillments Parameters

NAME
TYPE
DESCRIPTION
ordersWithFulfillments
Array<
BulkCreateOrderWithFulfillments
>

List of order IDs and their associated fulfillments' info.

Returns

Return Type:

Promise<
BulkCreateFulfillmentResponse
>
NAME
TYPE
DESCRIPTION
bulkActionMetadata
BulkActionMetadata

Bulk action metadata.

results
Array<
BulkOrderFulfillmentsResult
>

Items updated by bulk action.

Was this helpful?

Create a fulfillment for 2 different orders

Copy Code
1import { orderFulfillments } from 'wix-ecom-backend';
2
3/* Sample ordersWithFulfillments value:
4 * {
5 * ordersWithFulfillments: [
6 * {
7 * orderId: 'e613320a-8e8f-4f8f-9d87-b5edc9f99788',
8 * fulfillments: [{
9 * lineItems: [{
10 * _id: '00000000-0000-0000-0000-000000000003',
11 * quantity: 1
12 * }],
13 * trackingInfo: {
14 * trackingNumber: '93645',
15 * shippingProvider: 'canadaPost'
16 * }
17 * }]
18 * },
19 * {
20 * orderId: 'a6c3a817-579d-4cb5-8521-2fe53b2c4bf1',
21 * fulfillments: [{
22 * lineItems: [{
23 * _id: '00000000-0000-0000-0000-000000000001',
24 * quantity: 1
25 * }],
26 * trackingInfo: {
27 * trackingNumber: '28674',
28 * shippingProvider: 'usps'
29 * }
30 * }]
31 * }
32 * ]
33 * };
34 */
35
36export async function myBulkCreateFulfillmentsFunction(ordersWithFulfillments) {
37 try {
38 const newBulkFulfillments = await orderFulfillments.bulkCreateFulfillments(ordersWithFulfillments);
39
40 const firstNewFulfillments = newBulkFulfillments.results[0].ordersWithFulfillments.fulfillments;
41 const secondNewFulfillments = newBulkFulfillments.results[1].ordersWithFulfillments.fulfillments;
42
43 console.log("Success! Retrieved orders' fulfillments:", newBulkFulfillments);
44 return newBulkFulfillments;
45 } catch (error) {
46 console.error(error);
47 // Handle the error
48 }
49
50}
51
52/* Promise resolves to:
53 *
54 * {
55 * "results": [
56 * {
57 * "itemMetadata": {
58 * "_id": "e613320a-8e8f-4f8f-9d87-b5edc9f99788",
59 * "originalIndex": 0,
60 * "success": true
61 * },
62 * "ordersWithFulfillments": {
63 * "orderId": "e613320a-8e8f-4f8f-9d87-b5edc9f99788",
64 * "fulfillments": [
65 * {
66 * "_id": "397788c4-1c5b-40a3-9431-d4da8662a993",
67 * "_createdDate": "2023-03-07T14:26:33.276Z",
68 * "lineItems": [
69 * {
70 * "_id": "00000000-0000-0000-0000-000000000002",
71 * "quantity": 1
72 * }
73 * ],
74 * "trackingInfo": {
75 * "trackingNumber": "93645",
76 * "shippingProvider": "canadaPost",
77 * "trackingLink": "https://www.canadapost.ca/cpotools/apps/track/personal/findByTrackNumber?trackingNumber=93645"
78 * }
79 * },
80 * {
81 * "_id": "a875e4b7-c25d-4228-98e2-313ea6c07f95",
82 * "_createdDate": "2023-03-07T14:23:59.426Z",
83 * "lineItems": [
84 * {
85 * "_id": "00000000-0000-0000-0000-000000000001",
86 * "quantity": 1
87 * }
88 * ],
89 * "trackingInfo": {
90 * "trackingNumber": "93645",
91 * "shippingProvider": "canadaPost",
92 * "trackingLink": "https://www.canadapost.ca/cpotools/apps/track/personal/findByTrackNumber?trackingNumber=93645"
93 * }
94 * },
95 * {
96 * "_id": "e75bd872-69c9-427f-983a-280412161700",
97 * "_createdDate": "2023-03-07T14:30:21.535Z",
98 * "lineItems": [
99 * {
100 * "_id": "00000000-0000-0000-0000-000000000003",
101 * "quantity": 1
102 * }
103 * ],
104 * "trackingInfo": {
105 * "trackingNumber": "93645",
106 * "shippingProvider": "canadaPost",
107 * "trackingLink": "https://www.canadapost.ca/cpotools/apps/track/personal/findByTrackNumber?trackingNumber=93645"
108 * }
109 * }
110 * ]
111 * }
112 * },
113 * {
114 * "itemMetadata": {
115 * "_id": "a6c3a817-579d-4cb5-8521-2fe53b2c4bf1",
116 * "originalIndex": 1,
117 * "success": true
118 * },
119 * "ordersWithFulfillments": {
120 * "orderId": "a6c3a817-579d-4cb5-8521-2fe53b2c4bf1",
121 * "fulfillments": [
122 * {
123 * "_id": "a838877d-3f13-49f3-ab29-1cde478e0949",
124 * "_createdDate": "2023-03-07T14:30:21.535Z",
125 * "lineItems": [
126 * {
127 * "_id": "00000000-0000-0000-0000-000000000001",
128 * "quantity": 1
129 * }
130 * ],
131 * "trackingInfo": {
132 * "trackingNumber": "28674",
133 * "shippingProvider": "usps",
134 * "trackingLink": "https://tools.usps.com/go/TrackConfirmAction.action?tLabels=28674"
135 * }
136 * }
137 * ]
138 * }
139 * }
140 * ],
141 * "bulkActionMetadata": {
142 * "totalSuccesses": 2,
143 * "totalFailures": 0,
144 * "undetailedFailures": 0
145 * }
146 * }
147 *
148 */