Search.../

createCoupon( )

Creates a new coupon.

Description

The createCoupon() function returns a Promise that resolves to the ID of the the newly created coupon after it has been successfully created.

When creating a coupon, the specified couponInfo object must contain a value for exactly 1 of the following coupon properties. This defines the coupon type.

  • "moneyOffAmount"
  • "percentOffRate"
  • "fixedPriceAmount"
  • "buyXGetY"
  • "freeShipping"

When creating a new coupon, the specified couponInfo 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. You can apply a coupon to all items in a specific Wix application, a group within the application, or a single item within a group.

The following table lists the currently supported coupon scopes:

namespacegroupentityIdResult
stores----Applies to all store products
storesproductproduct IDApplies to the specific store product with the provided ID
storescollectioncollection IDApplies to the specific store collection with the provided ID
bookings----Applies to all bookings services
bookingsserviceservice IDApplies to the specific bookings service with the provided ID
eventseventevent IDApplies to the specific event with the provided ID
eventsticket--Applies to all event tickets
eventsticketticket IDApplies to the specific event ticket with the provided ID

Syntax

function createCoupon(couponInfo: CouponInfo): Promise<string>

createCoupon Parameters

NAME
TYPE
DESCRIPTION
couponInfo

CouponInfo

The information to use when creating the coupon.

Returns

Fulfilled - ID of the newly created coupon.

Return Type:

Promise<string>

Was this helpful?

Create a new coupon with options

Code Example

Copy Code
1import { coupons } from 'wix-marketing-backend';
2
3export function createCoupon() {
4 let couponInfo = {
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(couponInfo);
20}
21
22// Returns promise that resolves to:
23// bff1f257-5e7e-437d-9f86-098de337cae6
Create a new "money off" coupon

Code Example

Copy Code
1import { coupons } from 'wix-marketing-backend';
2
3export function createCoupon() {
4 let couponInfo = {
5 "name": "My Coupon",
6 "code": "myCouponCode",
7 "startTime": new Date(),
8 "scope": {
9 "namespace": "stores"
10 },
11 "moneyOffAmount": 10 // $10 off original price
12 };
13
14 return coupons.createCoupon(couponInfo);
15}
16
17// Returns promise that resolves to:
18// bff1f257-5e7e-437d-9f86-098de337cae6
Create a new free shipping coupon

Code Example

Copy Code
1import { coupons } from 'wix-marketing-backend';
2
3export function createCoupon() {
4 let couponInfo = {
5 "name": "My Coupon",
6 "code": "myCouponCode",
7 "startTime": new Date(),
8 "freeShipping": true
9 };
10
11 return coupons.createCoupon(couponInfo);
12}
13
14// Returns promise that resolves to:
15// bff1f257-5e7e-437d-9f86-098de337cae6
Create a new "buy x, get y" coupon

Code Example

Copy Code
1import { coupons } from 'wix-marketing-backend';
2
3export function createCoupon() {
4 let couponInfo = {
5 "name": "My Coupon",
6 "code": "myCouponCode",
7 "startTime": new Date(),
8 "scope": {
9 "namespace": "stores"
10 },
11 "buyXGetY": { // Buy 2 items, get 1 free
12 "x": 2,
13 "y": 1
14 }
15 };
16
17 return coupons.createCoupon(couponInfo);
18}
19
20// Returns promise that resolves to:
21// bff1f257-5e7e-437d-9f86-098de337cae6
Create a new coupon that applies to a specific store product

Code Example

Copy Code
1import { coupons } from 'wix-marketing-backend';
2
3export function createCoupon() {
4 let couponInfo = {
5 "name": "My Coupon",
6 "code": "myCouponCode",
7 "startTime": new Date(),
8 "scope": { // Coupon applies to the store product with the specified ID
9 "namespace": "stores",
10 "group": {
11 "name": "product",
12 "entityId": "3db41c71-6cb6-45f5-88fc-aaf05ed22e54"
13 }
14 },
15 "moneyOffAmount": 10
16 };
17
18 return coupons.createCoupon(couponInfo);
19}
20
21// Returns promise that resolves to:
22// bff1f257-5e7e-437d-9f86-098de337cae6
Create a new coupon that applies to all event tickets

Code Example

Copy Code
1import { coupons } from 'wix-marketing-backend';
2
3export function createCoupon() {
4 let couponInfo = {
5 "name": "My Coupon",
6 "code": "myCouponCode",
7 "startTime": new Date(),
8 "scope": { // Coupon applies to all event tickets
9 "namespace": "events",
10 "group": {
11 "name": "ticket"
12 }
13 },
14 "moneyOffAmount": 5 // $5 off original ticket price
15 };
16
17 return coupons.createCoupon(couponInfo);
18}
19
20// Returns promise that resolves to:
21// bff1f257-5e7e-437d-9f86-098de337cae6