Search.../

updateCoupon( )

Updates a coupon.

Description

The updateCoupon() function returns a Promise that resolves when the coupon is updated.

Only the properties passed in the specification object will be updated. All other properties will remain the same.

To remove a value from the coupon, pass its corresponding property with a value of null.

When updating a coupon, you cannot change the coupon's type. For example, if the coupon's type is moneyOffAmount, you cannot change it to fixedPriceAmount. You can update the coupon type's value. For example, you can change the value of moneyOffAmount from 5 to 10.

The coupon scope defines the items a coupon applies to. A coupon can apply to all items in a specific Wix application, a group within the application, or a single item within a group. See the introduction for a table of currently supported coupon scopes.

Admin Method

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

Syntax

function updateCoupon(_id: string, specification: Specification, fieldMask: Array<string>): Promise<void>

updateCoupon Parameters

NAME
TYPE
DESCRIPTION
_id
string

ID of the coupon to update.

specification
Specification

Coupon information to update.

fieldMask
Array<
string
>

Field mask of fields to update (required - passing an empty fieldMask will return an error). Valid field masks are any of those in the specification field.

Returns

Return Type:

Promise<
void
>

Was this helpful?

Update an existing coupon (dashboard page code)

Copy Code
1import { coupons } from 'wix-marketing.v2';
2
3export function updateCoupon(_id, fieldMask, specification) {
4 return coupons.updateCoupon(_id, fieldMask, specification);
5}
6
7// Returns a promise that is resolved when
8// the coupon is updated.
9
Update an existing coupon (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { coupons } from 'wix-marketing.v2';
3
4export const updateCoupon = webMethod(Permissions.Admin, (params) => {
5 const { _id, fieldMask, specification } = params;
6 return coupons.updateCoupon(_id, fieldMask, specification);
7});
8
9// Returns a promise that is resolved when
10// the coupon is updated.
Update a coupon's expiration date

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { coupons } from 'wix-marketing.v2';
3
4export const updateCoupon = webMethod(Permissions.Admin, () => {
5 let _id = "bff1f257-5e7e-437d-9f86-098de337cae6";
6
7 let fieldMask = "expirationTime"
8
9 let newExpirationDate = new Date();
10 newExpirationDate.setMonth(newExpirationDate.getMonth() + 1);
11
12 let specification = {
13 "expirationTime": newExpirationDate // Coupon ends in 1 month
14 };
15
16 return coupons.updateCouponFields(_id, fieldMask, specification);
17});
18
19// Returns a promise that is resolved when
20// the coupon is updated.