Search.../

createCoupon( )

Creates a new coupon.

Description

The createCoupon() function returns a Promise that resolves to an object containing the ID of the new 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
pricingPlans----Applies to all pricing plans
pricingPlansplanplan IDApplies to the specific pricing plan with the provided ID

Syntax

function createCoupon(couponInfo: CouponInfo): CouponId

createCoupon Parameters

NAME
TYPE
DESCRIPTION
couponInfo
CouponInfo

The information to use when creating the coupon.

Returns

Fulfilled - Object containing the ID of the new coupon.

Return Type:

Promise<CouponId>
NAME
TYPE
DESCRIPTION
id
string

ID of the new coupon.

Was this helpful?

Create a new coupon with options

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// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
Create a new "money off" coupon

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// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
Create a new free shipping coupon

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// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
Create a new "buy x, get y" coupon

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// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
Create a new coupon that applies to a specific store product

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// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
Create a new coupon that applies to all event tickets

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// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
Create a new "percent off" coupon that applies to all pricing plans

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