Search.../

createCoupon( )

Creates a new coupon.

Description

The createCoupon() function returns a Promise that resolves to the new coupon when it is created.

When creating a coupon, the specification object must contain values for name, code, startTime, and either scope or minimumSubtotal. The exception is for a freeShipping coupon type, for which you cannot apply a scope and minimumSubtotal is optional.

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.

The specification object must also contain a value for exactly 1 of the following coupon properties. This defines the coupon type.

  • "moneyOffAmount"
  • "percentOffRate"
  • "freeShipping"
  • "fixedPriceAmount"
  • "buyXGetY"
Admin Method

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

Syntax

function createCoupon(specification: Specification): Promise<CreateCouponResponse>

createCoupon Parameters

NAME
TYPE
DESCRIPTION
specification
Specification

Coupon to create.

Returns

Return Type:

Promise<
CreateCouponResponse
>
NAME
TYPE
DESCRIPTION
_id
string

ID of the newly created coupon.

Was this helpful?

Create a new coupon with options (dashboard page code)

Copy Code
1import { coupons } from 'wix-marketing.v2';
2
3export function createCoupon() {
4 let specification = {
5 "name": "My Coupon",
6 "code": "myCouponCode",
7 "startTime": new Date(),
8 "expirationTime": new Date(2020, 12, 31),
9 "usageLimit": 100,
10 "limitedToOneItem": true,
11 "limitPerCustomer": 1,
12 "active": true,
13 "scope": {
14 "namespace": "stores"
15 },
16 "moneyOffAmount": 10
17 };
18
19 return coupons.createCoupon(specification);
20}
21
22// Returns promise that resolves to:
23// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
24
Create a new coupon with options (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { coupons } from 'wix-marketing.v2';
3
4export const createCoupon = webMethod(Permissions.Admin, () => {
5 let specification = {
6 "name": "My Coupon",
7 "code": "myCouponCode",
8 "startTime": new Date(),
9 "expirationTime": new Date(2020, 12, 31),
10 "usageLimit": 100,
11 "limitedToOneItem": true,
12 "limitPerCustomer": 1,
13 "active": true,
14 "scope": {
15 "namespace": "stores"
16 },
17 "moneyOffAmount": 10
18 };
19
20 return coupons.createCoupon(specification);
21});
22
23// Returns promise that resolves to:
24// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
25
Create a new "money off" coupon

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { coupons } from 'wix-marketing.v2';
3
4export const createCoupon = webMethod(Permissions.Admin, () => {
5 let specification = {
6 "name": "My Coupon",
7 "code": "myCouponCode",
8 "startTime": new Date(),
9 "scope": {
10 "namespace": "stores"
11 },
12 "moneyOffAmount": 10 // $10 off original price
13 };
14
15 return coupons.createCoupon(specification);
16});
17
18// Returns promise that resolves to:
19// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
20
Create a new free shipping coupon

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { coupons } from 'wix-marketing.v2';
3
4export const createCoupon = webMethod(Permissions.Admin, () => {
5 let specification = {
6 "name": "My Coupon",
7 "code": "myCouponCode",
8 "startTime": new Date(),
9 "freeShipping": true
10 };
11
12 return coupons.createCoupon(specification);
13});
14
15// Returns promise that resolves to:
16// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
17
Create a new "buy x, get y" coupon

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { coupons } from 'wix-marketing.v2';
3
4export const createCoupon = webMethod(Permissions.Admin, () => {
5 let specification = {
6 "name": "My Coupon",
7 "code": "myCouponCode",
8 "startTime": new Date(),
9 "scope": {
10 "namespace": "stores"
11 },
12 "buyXGetY": { // Buy 2 items, get 1 free
13 "x": 2,
14 "y": 1
15 }
16 };
17
18 return coupons.createCoupon(specification);
19});
20
21// Returns promise that resolves to:
22// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
23
Create a new coupon that applies to a specific store product

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { coupons } from 'wix-marketing.v2';
3
4export const createCoupon = webMethod(Permissions.Admin, () => {
5 let specification = {
6 "name": "My Coupon",
7 "code": "myCouponCode",
8 "startTime": new Date(),
9 "scope": { // Coupon applies to the store product with the specified ID
10 "namespace": "stores",
11 "group": {
12 "name": "product",
13 "entityId": "3db41c71-6cb6-45f5-88fc-aaf05ed22e54"
14 }
15 },
16 "moneyOffAmount": 10
17 };
18
19 return coupons.createCoupon(specification);
20});
21
22// Returns promise that resolves to:
23// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
24
Create a new coupon that applies to all event tickets

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { coupons } from 'wix-marketing.v2';
3
4export const createCoupon = webMethod(Permissions.Admin, () => {
5 let specification = {
6 "name": "My Coupon",
7 "code": "myCouponCode",
8 "startTime": new Date(),
9 "scope": { // Coupon applies to all event tickets
10 "namespace": "events",
11 "group": {
12 "name": "ticket"
13 }
14 },
15 "moneyOffAmount": 5 // $5 off original ticket price
16 };
17
18 return coupons.createCoupon(specification);
19});
20
21// Returns promise that resolves to:
22// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
23
Create a new "percent off" coupon that applies to all pricing plans

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { coupons } from 'wix-marketing.v2';
3
4export const createCoupon = webMethod(Permissions.Admin, () => {
5 let specification = {
6 "name": "Summer Sale 20%",
7 "code": "SUMMER20",
8 "startTime": new Date(),
9 "expirationTime": new Date('Sep 23, 2022 23:59:00'),
10 "scope": { // Coupon applies to all pricing plans
11 "namespace": "pricingPlans"
12 },
13 "percentOffRate": 20
14 };
15
16 return coupons.createCoupon(specification);
17});
18
19// Returns promise that resolves to:
20// {"_id": "c2750c68-c253-42ce-85a4-2c9d09bfbcd8"}
21