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"
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
Coupon to create.
Returns
Return Type:
NAME
TYPE
DESCRIPTION
ID of the newly created coupon.
Was this helpful?
1import { coupons } from 'wix-marketing.v2';23export 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": 1017 };1819 return coupons.createCoupon(specification);20}2122// Returns promise that resolves to:23// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}24
1import { Permissions, webMethod } from 'wix-web-module';2import { coupons } from 'wix-marketing.v2';34export 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": 1018 };1920 return coupons.createCoupon(specification);21});2223// Returns promise that resolves to:24// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}25
1import { Permissions, webMethod } from 'wix-web-module';2import { coupons } from 'wix-marketing.v2';34export 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 price13 };1415 return coupons.createCoupon(specification);16});1718// Returns promise that resolves to:19// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}20
1import { Permissions, webMethod } from 'wix-web-module';2import { coupons } from 'wix-marketing.v2';34export const createCoupon = webMethod(Permissions.Admin, () => {5 let specification = {6 "name": "My Coupon",7 "code": "myCouponCode",8 "startTime": new Date(),9 "freeShipping": true10 };1112 return coupons.createCoupon(specification);13});1415// Returns promise that resolves to:16// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}17
1import { Permissions, webMethod } from 'wix-web-module';2import { coupons } from 'wix-marketing.v2';34export 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 free13 "x": 2,14 "y": 115 }16 };1718 return coupons.createCoupon(specification);19});2021// Returns promise that resolves to:22// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}23
1import { Permissions, webMethod } from 'wix-web-module';2import { coupons } from 'wix-marketing.v2';34export 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 ID10 "namespace": "stores",11 "group": {12 "name": "product",13 "entityId": "3db41c71-6cb6-45f5-88fc-aaf05ed22e54"14 }15 },16 "moneyOffAmount": 1017 };1819 return coupons.createCoupon(specification);20});2122// Returns promise that resolves to:23// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}24
1import { Permissions, webMethod } from 'wix-web-module';2import { coupons } from 'wix-marketing.v2';34export 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 tickets10 "namespace": "events",11 "group": {12 "name": "ticket"13 }14 },15 "moneyOffAmount": 5 // $5 off original ticket price16 };1718 return coupons.createCoupon(specification);19});2021// Returns promise that resolves to:22// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}23
1import { Permissions, webMethod } from 'wix-web-module';2import { coupons } from 'wix-marketing.v2';34export 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 plans11 "namespace": "pricingPlans"12 },13 "percentOffRate": 2014 };1516 return coupons.createCoupon(specification);17});1819// Returns promise that resolves to:20// {"_id": "c2750c68-c253-42ce-85a4-2c9d09bfbcd8"}21