> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# createCoupon

# Package: @wix/marketing

# Namespace: coupons

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/coupons/coupons/create-a-coupon.md

## Permission Scopes:
Manage Coupons: SCOPE.DC-COUPONS.MANAGE-COUPONS

## Introduction

Creates a new coupon.

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 [valid scope values](https://dev.wix.com/api/rest/coupons/coupons/valid-scope-values).

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"`

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.marketing.coupons.createCoupon(specification)
 Description: Creates a new coupon.  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 [valid scope values](https://dev.wix.com/api/rest/coupons/coupons/valid-scope-values).  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"`
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  specification
 Method parameters: 
   param name: specification | type: Specification | description: Coupon information | required: true 
    - ONE-OF: - required: true
     - name: scope | type: Scope | description: Specifies the type of line items this coupon will apply to. See [valid scope values](https://dev.wix.com/api/rest/coupons/coupons/valid-scope-values).  
        - name: namespace | type: string | description: Scope namespace (Wix Stores, Wix Bookings, Wix Events, Wix Pricing Plans)  
        - name: group | type: Group | description: Coupon scope's applied group (e.g., event or ticket in Wix Events)  
           - name: name | type: string | description: Coupon scope's group (e.g., product or collection in Wix Stores). See [valid scope values](https://dev.wix.com/api/rest/coupons/coupons/valid-scope-values).  
           - name: entityId | type: string | description: Item GUID (when the coupon scope is limited to just one item).  
     - name: minimumSubtotal | type: number | description: Limit the coupon to carts with a subtotal above this number.  
     - name: moneyOffAmount | type: number | description: Discount as a fixed amount.  
     - name: percentOffRate | type: number | description: Discount as a percentage.  
     - name: freeShipping | type: boolean | description: Free shipping.  If `true`, the coupon applies to all items in all `namespaces`.  
     - name: fixedPriceAmount | type: number | description: Fixed sale price.  
     - name: buyXGetY | type: BuyXGetY | description: Receive free products when making a purchase.  For example, purchase `x` number of products and receive `y` number of products for free.  
        - name: x | type: integer | description: Number of purchased items required to receive free items.  
        - name: y | type: integer | description: Number of items received for free if required number of items were purchased.  
        - name: name | type: string | description: Name of coupon.  
        - name: code | type: string | description: Coupon code. Must be unique for all coupons on your site.  Max: 20 characters  
        - name: startTime | type: string | description: Coupon valid from this date and time, in milliseconds. For example, `"1554066000000"`.  | validation: minimum 1000000000000, format int64
        - name: expirationTime | type: string | description: Coupon expires at this date and time, in milliseconds. For example, `"1554325199999"`.  | validation: minimum 1000000000000, format int64
        - name: usageLimit | type: integer | description: Maximum number of times the coupon can be used.  >**Note:** Multiple purchases by the same customer or purchases by different customers are both counted toward `usageLimit`.  | validation: format int32
        - name: limitPerCustomer | type: integer | description: Maximum number of times the coupon can be used per customer.  | validation: format int32
        - name: limitedToOneItem | type: boolean | description: Whether the coupon is limited to one item.  If `true` and a customer pays for multiple items, the discount applies to only the lowest priced item. Coupons with a `bookings` `scope.namespace` are always limited to one item.  
        - name: appliesToSubscriptions | type: boolean | description: Whether the coupon applies to subscription products.  
        - name: discountedCycleCount | type: integer | description: Specifies the amount of discounted cycles for a subscription item.  + Can only be set when `scope.namespace = pricingPlans`. + If `discountedCycleCount` is empty, the coupon applies to all available cycles. + `discountedCycleCount` is ignored if `appliesToSubscriptions = true`.  Max: `999`  | validation: format int32
        - name: active | type: boolean | description: Whether the coupon is currently [active](https://support.wix.com/en/article/wix-stores-activating-and-deactivating-coupons).  Default: `true`  
        - name: type | type: string | description: Coupon type. Read-only.  
        - name: tags | type: array<string> | description: Tags for categorizing the coupon.  | validation: maxItems 100, maxLength 255
 Return type: PROMISE<CreateCouponResponse>
  - name: _id | type: string | description: GUID of the newly created coupon.  


```

### Examples

### Create a new coupon with options
```javascript
import { coupons } from '@wix/marketing';

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 "percent off" coupon that applies to all pricing plans (with elevated permissions)
```javascript
import { coupons } from '@wix/marketing';
import { auth } from '@wix/essentials';

const elevatedCreateCoupon = auth.elevate(coupons.createCoupon);

export async function createCoupon() {
  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 elevatedCreateCoupon(specification);
}

// Returns promise that resolves to:
// {"_id": "c2750c68-c253-42ce-85a4-2c9d09bfbcd8"}
```

### Create a new "percent off" coupon that applies to all pricing plans
```javascript
import { coupons } from '@wix/marketing';

export async function createCoupon() {
  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"}
```

### Create a new coupon that applies to all event tickets (with elevated permissions)
```javascript
import { coupons } from '@wix/marketing';
import { auth } from '@wix/essentials';

const elevatedCreateCoupon = auth.elevate(coupons.createCoupon);

export async function createCoupon() {
  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 elevatedCreateCoupon(specification);
}

// Returns promise that resolves to:
// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}

```

### Create a new coupon that applies to all event tickets
```javascript
import { coupons } from '@wix/marketing';

export async function createCoupon() {
  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 coupon that applies to a specific store product (with elevated permissions)
```javascript
import { coupons } from '@wix/marketing';
import { auth } from '@wix/essentials';

const elevatedCreateCoupon = auth.elevate(coupons.createCoupon);

export async function createCoupon() {
  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 elevatedCreateCoupon(specification);
}

// Returns promise that resolves to:
// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}

```

### Create a new coupon that applies to a specific store product
```javascript
import { coupons } from '@wix/marketing';

export async function createCoupon() {
  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 "buy x, get y" coupon (with elevated permissions)
```javascript
import { coupons } from '@wix/marketing';
import { auth } from '@wix/essentials';

const elevatedCreateCoupon = auth.elevate(coupons.createCoupon);

export async function createCoupon() {
  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 elevatedCreateCoupon(specification);
}

// Returns promise that resolves to:
// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
```

### Create a new "buy x, get y" coupon
```javascript
import { coupons } from '@wix/marketing';

export async function createCoupon() {
  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-8a3-8bf90b3fc4e6"}
```

### Create a new free shipping coupon (with elevated permissions)
```javascript
import { coupons } from '@wix/marketing';
import { auth } from '@wix/essentials';

const elevatedCreateCoupon = auth.elevate(coupons.createCoupon);

export async function createCoupon() {
  let specification = {
    "name": "My Coupon",
    "code": "myCouponCode",
    "startTime": `${new Date().getTime()}`,
    "freeShipping": true
  };

  return elevatedCreateCoupon(specification);
}

// Returns promise that resolves to:
// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
```

### Create a new free shipping coupon
```javascript
import { coupons } from '@wix/marketing';

export async function createCoupon() {
  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 "money off" coupon (with elevated permissions)
```javascript
import { coupons } from '@wix/marketing';
import { auth } from '@wix/essentials';

const elevatedCreateCoupon = auth.elevate(coupons.createCoupon);

export async function createCoupon() {
  let specification = {
    "name": "My Coupon",
    "code": "myCouponCode",
    "startTime": `${new Date().getTime()}`,
    "scope": {
      "namespace": "stores"
    },
    "moneyOffAmount": 10 // $10 off original price
  };

  return elevatedCreateCoupon(specification);
}

// Returns promise that resolves to:
// {"_id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
```

### Create a new "money off" coupon
```javascript
import { coupons } from '@wix/marketing';

export async function createCoupon() {
  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 coupon with options (with elevated permissions)
```javascript
import { coupons } from '@wix/marketing';
import { auth } from '@wix/essentials';

const elevatedCreateCoupon = auth.elevate(coupons.createCoupon);

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 elevatedCreateCoupon(specification);
}

// Returns promise that resolves to:
// {"id": "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"}
```

### createCoupon (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { coupons } from '@wix/marketing';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { coupons },
  // Include the auth strategy and host as relevant
});


async function createCoupon(specification) {
  const response = await myWixClient.coupons.createCoupon(specification);
};
```

---