> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: createCoupon(specification: Specification) # Method package: wixMarketingV2 # Method menu location: wixMarketingV2 --> coupons --> createCoupon # Method Link: https://dev.wix.com/docs/velo/apis/wix-marketing-v2/coupons/create-coupon.md # Method Description: Creates a new coupon. 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](#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"` # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Create a new coupon with options (dashboard page code)@description: ```javascript import { coupons } from 'wix-marketing.v2'; export function createCoupon() { let specification = { "name": "My Coupon", "code": "myCouponCode", "startTime": `${new Date().getTime()}`, "expirationTime": `${new Date(2030, 12, 31).getTime()}`, "usageLimit": 100, "limitedToOneItem": true, "limitPerCustomer": 1, "active": true, "scope": { "namespace": "stores" }, "moneyOffAmount": 10 }; return coupons.createCoupon(specification); } // Returns promise that resolves to: // {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"} ``` ## Create a new coupon with options (export from backend code)@description: ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { coupons } from 'wix-marketing.v2'; export const createCoupon = webMethod(Permissions.Admin, () => { let specification = { "name": "My Coupon", "code": "myCouponCode", "startTime": `${new Date().getTime()}`, "expirationTime": `${new Date(2030, 12, 31).getTime()}`, "usageLimit": 100, "limitedToOneItem": true, "limitPerCustomer": 1, "active": true, "scope": { "namespace": "stores" }, "moneyOffAmount": 10 }; return coupons.createCoupon(specification); }); // Returns promise that resolves to: // {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"} ``` ## Create a new "money off" coupon @description: ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { coupons } from 'wix-marketing.v2'; export const createCoupon = webMethod(Permissions.Admin, () => { let specification = { "name": "My Coupon", "code": "myCouponCode", "startTime": `${new Date().getTime()}`, "scope": { "namespace": "stores" }, "moneyOffAmount": 10 // $10 off original price }; return coupons.createCoupon(specification); }); // Returns promise that resolves to: // {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"} ``` ## Create a new free shipping coupon @description: ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { coupons } from 'wix-marketing.v2'; export const createCoupon = webMethod(Permissions.Admin, () => { let specification = { "name": "My Coupon", "code": "myCouponCode", "startTime": `${new Date().getTime()}`, "freeShipping": true }; return coupons.createCoupon(specification); }); // Returns promise that resolves to: // {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"} ``` ## Create a new "buy x, get y" coupon @description: ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { coupons } from 'wix-marketing.v2'; export const createCoupon = webMethod(Permissions.Admin, () => { let specification = { "name": "My Coupon", "code": "myCouponCode", "startTime": `${new Date().getTime()}`, "scope": { "namespace": "stores" }, "buyXGetY": { // Buy 2 items, get 1 free "x": 2, "y": 1 } }; return coupons.createCoupon(specification); }); // Returns promise that resolves to: // {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"} ``` ## Create a new coupon that applies to a specific store product @description: ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { coupons } from 'wix-marketing.v2'; export const createCoupon = webMethod(Permissions.Admin, () => { let specification = { "name": "My Coupon", "code": "myCouponCode", "startTime": `${new Date().getTime()}`, "scope": { // Coupon applies to the store product with the specified ID "namespace": "stores", "group": { "name": "product", "entityId": "3db41c71-6cb6-45f5-88fc-aaf05ed22e54" } }, "moneyOffAmount": 10 }; return coupons.createCoupon(specification); }); // Returns promise that resolves to: // {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"} ``` ## Create a new coupon that applies to all event tickets @description: ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { coupons } from 'wix-marketing.v2'; export const createCoupon = webMethod(Permissions.Admin, () => { let specification = { "name": "My Coupon", "code": "myCouponCode", "startTime": `${new Date().getTime()}`, "scope": { // Coupon applies to all event tickets "namespace": "events", "group": { "name": "ticket" } }, "moneyOffAmount": 5 // $5 off original ticket price }; return coupons.createCoupon(specification); }); // Returns promise that resolves to: // {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"} ``` ## Create a new "percent off" coupon that applies to all pricing plans @description: ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { coupons } from 'wix-marketing.v2'; export const createCoupon = webMethod(Permissions.Admin, () => { let specification = { "name": "Summer Sale 20%", "code": "SUMMER20", "startTime": `${new Date().getTime()}`, "expirationTime": `${new Date(2030, 12, 31).getTime()}`, "scope": { // Coupon applies to all pricing plans "namespace": "pricingPlans" }, "percentOffRate": 20 }; return coupons.createCoupon(specification); }); // Returns promise that resolves to: // {"_id": "c2750c68-c253-42ce-85a4-2c9d09bfbcd8"} ``` ---