Introduction

The Orders API allows apps or site owners to customize management of the order lifecycle, including viewing, updating, and canceling. In the dashboard, business staff can create new orders, view and edit existing orders, track fulfillment, and manage the payments cycle.

An order holds information about purchased items, price and tax summaries, shipping and billing information, any applied discounts, and the status of payment and fulfillment.

With the Orders API you can:

  • Get and search for orders.
  • Update and cancel an order.
  • Create an order for your records.
  • Listen to events when an order is approved, updated, or canceled.
  • Listen to events when an order's transactions are updated. This event is part of the Order Transactions API.

To use the Orders API, import { orders } from the wix-ecom-backend module:

Copy
import { orders } from "wix-ecom-backend";

Permissions information

Functions in the Orders API are restricted and only run if you elevate permissions using the wix-auth elevate() function.

Warning: Elevating a function allows it to be called by any site visitor. Exercise caution to prevent security vulnerabilities.

Did this help?

bulkUpdateOrders( )


Updates up to 100 orders.

The bulkUpdateOrders() function returns a Promise that resolves when the specified orders' information is updated.

Currently, the following fields can be updated:

  • order.buyerInfo.email
  • order.buyerLanguage
  • order.weightUnit
  • order.billingInfo.address
  • order.billingInfo.contactDetails
  • order.archived
  • order.attributionSource
  • order.seenByAHuman
  • order.recipientInfo.address
  • order.recipientInfo.contactDetails
  • order.shippingInfo.logistics.shippingDestination.address
  • order.shippingInfo.logistics.shippingDestination.contactDetails

To update a field's value, include the new value in the orders.order object in the method parameters. To remove a field's value, pass null.

Note: Removing buyerInfo or contactDetails fields results in an error.

To update an order's payment status, use updatePaymentStatus( ).

Authentication

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

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Orders
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function bulkUpdateOrders(
  orders: Array<MaskedOrder>,
  options: BulkUpdateOrdersOptions,
): Promise<BulkUpdateOrdersResponse>;
Method Parameters
ordersArray<MaskedOrder>Required

Orders to update.


optionsBulkUpdateOrdersOptions
Returns
Return Type:Promise<BulkUpdateOrdersResponse>

Bulk updates archived status for 2 orders.

JavaScript
import { orders } from "wix-ecom-backend"; /* Sample ordersToUpdate value: * [ * { * order: { * id: 'efc0f204-d83a-4391-b576-e9cf816f6bc9', * archived: true * } * }, * { * order: { * id: '6bfb7f73-3269-41d6-b396-64f6bb5947ff', * archived: true * } * } * ] */ /* Sample options value: * { returnEntity: false } */ export async function myBulkUpdateOrders(ordersToUpdate, options) { try { const bulkUpdateOrdersResponse = await orders.bulkUpdateOrders( ordersToUpdate, options, ); console.log("Bulk update orders response:", bulkUpdateOrdersResponse); return bulkUpdateOrdersResponse; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "results": [ * { * "itemMetadata": { * "id": "efc0f204-d83a-4391-b576-e9cf816f6bc9", * "originalIndex": 0, * "success": true * } * }, * { * "itemMetadata": { * "id": "6bfb7f73-3269-41d6-b396-64f6bb5947ff", * "originalIndex": 1, * "success": true * } * } * ], * "bulkActionMetadata": { * "totalSuccesses": 2, * "totalFailures": 0, * "undetailedFailures": 0 * } * } */
Errors

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

Did this help?

cancelOrder( )


Cancels an order.

The cancelOrder() function returns a Promise that resolves when the specified order is canceled and the order.status field changes to CANCELED.

Authentication

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

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Orders
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function cancelOrder(
  _id: string,
  options: CancelOrderOptions,
): Promise<CancelOrderResponse>;
Method Parameters
_idstringRequired

Order ID.


optionsCancelOrderOptions
Returns
Return Type:Promise<CancelOrderResponse>
JavaScript
import { orders } from "wix-ecom-backend"; async function cancelOrder(id, options) { try { const result = await orders.cancelOrder(id, options); return result; } catch (error) { console.error(error); // Handle the error } }
Errors
428Failed Precondition

There is 1 error with this status code.

This method may also return standard errors. Learn more about standard Wix errors.

Did this help?

createOrder( )


Creates an order.

The createOrder() function returns a Promise that resolves when the order is created.

Notes:

  • If an item is digital - lineItems[i].itemType.preset: DIGITAL - then lineItems[i].digitalFile must be provided.
  • If lineItems[i].id is passed, it must be either a valid GUID, or empty.
Authentication

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

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Orders
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function createOrder(order: Order, options: CreateOrderOptions): Promise<Order>;
Method Parameters
orderOrderRequired

Order info.


optionsCreateOrderOptions
Returns
Return Type:Promise<Order>
JavaScript
import { orders } from "wix-ecom-backend"; async function createOrder(order, options) { try { const result = await orders.createOrder(order, options); return result; } catch (error) { console.error(error); // Handle the error } }
Errors
428Failed Precondition

There is 1 error with this status code.

This method may also return standard errors. Learn more about standard Wix errors.

Did this help?

getOrder( )


Retrieves an order.

The getOrder() function returns a Promise that resolves when the specified order is retrieved.

To retrieve an order's payment and refund details, including amounts, payment methods, and payment statuses, pass the order ID to listTransactionsForSingleOrder( ).

Authentication

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

Permissions
Manage eCommerce - all permissions
Read eCommerce - all read permissions
Manage Stores - all permissions
Read Stores - all read permissions
Manage Orders
Read Orders
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function getOrder(_id: string): Promise<Order>;
Method Parameters
_idstringRequired

ID of the order to retrieve.

Returns
Return Type:Promise<Order>
Get an order (export from backend code)
JavaScript
/***************************************** * Backend code - my-backend-file.web.js * ****************************************/ import { Permissions, webMethod } from "wix-web-module"; import { orders } from "wix-ecom-backend"; export const myGetOrderFunction = webMethod( Permissions.Anyone, async (orderId) => { try { const retrievedOrder = await orders.getOrder(orderId); console.log("Success! Retrieved order:", retrievedOrder); return retrievedOrder; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myGetOrderFunction } from "backend/my-backend-file.web"; // Sample orderId: const orderId = "67668940-527d-4465-94c6-5475d8c7a412"; myGetOrderFunction(orderId) .then((order) => { const orderNumber = order.number; const orderId = order._id; console.log("Success! Retrieved order:", order); return order; }) .catch((error) => { console.error(error); // Handle the error }); /* * Promise resolves to: * * { * "_id": "67668940-527d-4465-94c6-5475d8c7a412", * "number": "10124", * "_createdDate": "2022-07-31T13:42:13.136Z", * "_updatedDate": "2022-07-31T14:58:11.663Z", * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "productName": { * "original": "Brazilian Arabica", * "translated": "Brazilian Arabica" * }, * "catalogReference": { * "catalogItemId": "0614129c-8777-9f3b-4dfe-b80a54df10d5", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", * "options": { * "options": { * "Weight": "500g", * "Ground for": "Stovetop" * }, * "variantId": "00000000-0000-003f-0005-a316f7c67df7", * "customTextFields": { * "What would you like written on the custom label?": "Enjoy our finest coffee." * } * } * }, * "quantity": 1, * "totalDiscount": { * "amount": "0", * "formattedAmount": "$0.00" * }, * "descriptionLines": [ * { * "name": { * "original": "Weight", * "translated": "Weight" * }, * "plainText": { * "original": "500g", * "translated": "500g" * }, * "lineType": "PLAIN_TEXT", * "plainTextValue": { * "original": "500g", * "translated": "500g" * } * }, * { * "name": { * "original": "Ground for", * "translated": "Ground for" * }, * "plainText": { * "original": "Stovetop", * "translated": "Stovetop" * }, * "lineType": "PLAIN_TEXT", * "plainTextValue": { * "original": "Stovetop", * "translated": "Stovetop" * } * }, * { * "name": { * "original": "What would you like written on the custom label?", * "translated": "What would you like written on the custom label?" * }, * "plainText": { * "original": "Enjoy our finest coffee.", * "translated": "Enjoy our finest coffee." * }, * "lineType": "PLAIN_TEXT", * "plainTextValue": { * "original": "Enjoy our finest coffee.", * "translated": "Enjoy our finest coffee." * } * } * ], * "image": "wix:image://v1/nsplsh_306d666a306a4a74306459~mv2_d_4517_2992_s_4_2.jpg#originWidth=4517&originHeight=2992", * "physicalProperties": { * "weight": 0.5, * "shippable": true * }, * "itemType": { * "preset": "PHYSICAL" * }, * "fulfillerId": "85e29287-a5bf-4c25-b303-a2ddc9d975e2", * "refundQuantity": 0, * "price": { * "amount": "48.75", * "formattedAmount": "$48.75" * }, * "priceBeforeDiscounts": { * "amount": "48.75", * "formattedAmount": "$48.75" * }, * "totalPriceBeforeTax": { * "amount": "48.75", * "formattedAmount": "$48.75" * }, * "totalPriceAfterTax": { * "amount": "50.70", * "formattedAmount": "$50.70" * }, * "paymentOption": "FULL_PAYMENT_ONLINE", * "taxDetails": { * "taxableAmount": { * "amount": "48.75", * "formattedAmount": "$48.75" * }, * "taxRate": "0.04", * "totalTax": { * "amount": "1.95", * "formattedAmount": "$1.95" * } * } * } * ], * "buyerInfo": { * "contactId": "f61f30cd-7474-47b7-95a2-339c0fcacbd3", * "email": "janedoe@gmail.com", * "visitorId": "b52ec002-40dd-469c-9f9f-833988e8048d" * }, * "paymentStatus": "PAID", * "fulfillmentStatus": "NOT_FULFILLED", * "buyerLanguage": "en", * "weightUnit": "LB", * "currency": "USD", * "taxIncludedInPrices": false, * "priceSummary": { * "subtotal": { * "amount": "48.75", * "formattedAmount": "$48.75" * }, * "shipping": { * "amount": "5.0", * "formattedAmount": "$5.00" * }, * "tax": { * "amount": "1.95", * "formattedAmount": "$1.95" * }, * "discount": { * "amount": "0", * "formattedAmount": "$0.00" * }, * "totalPrice": { * "amount": "55.70", * "formattedAmount": "$55.70" * }, * "total": { * "amount": "55.70", * "formattedAmount": "$55.70" * }, * "totalWithGiftCard": { * "amount": "55.70", * "formattedAmount": "$55.70" * }, * "totalWithoutGiftCard": { * "amount": "55.70", * "formattedAmount": "$55.70" * }, * "totalAdditionalFees": { * "amount": "0", * "formattedAmount": "$0.00" * } * }, * "billingInfo": { * "address": { * "addressLine1": "525 5th Avenue", * "city": "New York", * "subdivision": "US-NY", * "country": "US", * "postalCode": "10173" * }, * "contactDetails": { * "firstName": "Jane", * "lastName": "Doe", * "phone": "0555555555" * } * }, * "shippingInfo": { * "carrierId": "c8a08776-c095-4dec-8553-8f9698d86adc", * "code": "a0fde0a4-6f4e-3716-64be-c0acbde1696a", * "title": "U.S Shipping", * "logistics": { * "deliveryTime": "3 - 5 business days", * "shippingDestination": { * "address": { * "addressLine1": "525 5th Avenue", * "city": "New York", * "subdivision": "US-NY", * "country": "US", * "postalCode": "10173" * }, * "contactDetails": { * "firstName": "Jane", * "lastName": "Doe", * "phone": "0555555555" * } * } * }, * "cost": { * "price": { * "amount": "5", * "formattedAmount": "$5.00" * }, * "totalPriceBeforeTax": { * "amount": "5", * "formattedAmount": "$5.00" * }, * "totalPriceAfterTax": { * "amount": "5.0", * "formattedAmount": "$5.00" * }, * "taxDetails": { * "taxRate": "0.0", * "totalTax": { * "amount": "0.0", * "formattedAmount": "$0.00" * } * }, * "discount": { * "amount": "0", * "formattedAmount": "$0.00" * } * }, * "region": { * "name": "Region 3" * } * }, * "buyerNote": "This is a buyerNote", * "status": "APPROVED", * "taxSummary": { * "totalTax": { * "amount": "1.95", * "formattedAmount": "$1.95" * }, * "manualTaxRate": "0.04" * }, * "appliedDiscounts": [], * "activities": [], * "attributionSource": "UNSPECIFIED", * "createdBy": { * "visitorId": "b52ec002-40dd-469c-9f9f-833988e8048d" * }, * "channelInfo": { * "type": "WEB" * }, * "checkoutId": "62d01935-e0d3-4063-9e78-da099462e90c", * "customFields": [], * "cartId": "52fec024-4379-4a96-9237-9660030be6fe", * "payNow": { * "subtotal": { * "amount": "48.75", * "formattedAmount": "$48.75" * }, * "shipping": { * "amount": "5.0", * "formattedAmount": "$5.00" * }, * "tax": { * "amount": "1.95", * "formattedAmount": "$1.95" * }, * "discount": { * "amount": "0", * "formattedAmount": "$0.00" * }, * "totalPrice": { * "amount": "55.70", * "formattedAmount": "$55.70" * }, * "total": { * "amount": "55.70", * "formattedAmount": "$55.70" * }, * "totalWithGiftCard": { * "amount": "55.70", * "formattedAmount": "$55.70" * }, * "totalWithoutGiftCard": { * "amount": "55.70", * "formattedAmount": "$55.70" * } * }, * "balanceSummary": { * "balance": { * "amount": "0.0", * "formattedAmount": "$0.00" * } * }, * "additionalFees": [] * } * */
Errors

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

Did this help?

updateOrder( )


Updates an order.

The updateOrder() function returns a Promise that resolves when the specified order's information is updated.

Currently, the following fields can be updated:

  • order.buyerInfo.email
  • order.buyerLanguage
  • order.weightUnit
  • order.billingInfo.address
  • order.billingInfo.contactDetails
  • order.archived
  • order.attributionSource
  • order.seenByAHuman
  • order.recipientInfo.address
  • order.recipientInfo.contactDetails
  • order.shippingInfo.logistics.shippingDestination.address
  • order.shippingInfo.logistics.shippingDestination.contactDetails

To update a field's value, include the new value in the order object in the method parameters. To remove a field's value, pass null.

Note: Removing buyerInfo or contactDetails fields results in an error.

To update an order's payment status, use updatePaymentStatus( ).

Authentication

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

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Orders
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function updateOrder(
  _id: string,
  order: UpdateOrder,
  options: UpdateOrderOptions,
): Promise<Order>;
Method Parameters
_idstringRequired

Order ID.


orderUpdateOrderRequired

optionsUpdateOrderOptions
Returns
Return Type:Promise<Order>
JavaScript
import { orders } from "wix-ecom-backend"; async function updateOrder(id, order, options) { try { const result = await orders.updateOrder(id, order, options); return result; } catch (error) { console.error(error); // Handle the error } }
Errors

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

Did this help?