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:
namespace | group | entityId | Result |
---|---|---|---|
stores | -- | -- | Applies to all store products |
stores | product | product ID | Applies to the specific store product with the provided ID |
stores | collection | collection ID | Applies to the specific store collection with the provided ID |
bookings | -- | -- | Applies to all bookings services |
bookings | service | service ID | Applies to the specific bookings service with the provided ID |
events | event | event ID | Applies to the specific event with the provided ID |
events | ticket | -- | Applies to all event tickets |
events | ticket | ticket ID | Applies to the specific event ticket with the provided ID |
pricingPlans | -- | -- | Applies to all pricing plans |
pricingPlans | plan | plan ID | Applies to the specific pricing plan with the provided ID |
Syntax
function createCoupon(couponInfo: CouponInfo): CouponId
createCoupon Parameters
NAME
TYPE
DESCRIPTION
The information to use when creating the coupon.
Returns
Fulfilled - Object containing the ID of the new coupon.
Return Type:
NAME
TYPE
DESCRIPTION
ID of the new coupon.
Was this helpful?
1import { coupons } from 'wix-marketing-backend';23export 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": 1017 };1819 return coupons.createCoupon(couponInfo);20}2122// Returns promise that resolves to:23// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
1import { coupons } from 'wix-marketing-backend';23export 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 price12 };1314 return coupons.createCoupon(couponInfo);15}1617// Returns promise that resolves to:18// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
1import { coupons } from 'wix-marketing-backend';23export function createCoupon() {4 let couponInfo = {5 "name": "My Coupon",6 "code": "myCouponCode",7 "startTime": new Date(),8 "freeShipping": true9 };1011 return coupons.createCoupon(couponInfo);12}1314// Returns promise that resolves to:15// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
1import { coupons } from 'wix-marketing-backend';23export 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 free12 "x": 2,13 "y": 114 }15 };1617 return coupons.createCoupon(couponInfo);18}1920// Returns promise that resolves to:21// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
1import { coupons } from 'wix-marketing-backend';23export 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 ID9 "namespace": "stores",10 "group": {11 "name": "product",12 "entityId": "3db41c71-6cb6-45f5-88fc-aaf05ed22e54"13 }14 },15 "moneyOffAmount": 1016 };1718 return coupons.createCoupon(couponInfo);19}2021// Returns promise that resolves to:22// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
1import { coupons } from 'wix-marketing-backend';23export function createCoupon() {4 let couponInfo = {5 "name": "My Coupon",6 "code": "myCouponCode",7 "startTime": new Date(),8 "scope": { // Coupon applies to all event tickets9 "namespace": "events",10 "group": {11 "name": "ticket"12 }13 },14 "moneyOffAmount": 5 // $5 off original ticket price15 };1617 return coupons.createCoupon(couponInfo);18}1920// Returns promise that resolves to:21// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
1import { coupons } from 'wix-marketing-backend';23export 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 plans10 "namespace": "pricingPlans"11 },12 "percentOffRate": 2013 };1415 return coupons.createCoupon(couponInfo);16}1718// Returns promise that resolves to:19// {"id": "c2750c68-c253-42ce-85a4-2c9d09bfbcd8"}