> 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 # CreateDiscountRule # Package: discounts # Namespace: DiscountRuleService # Method link: https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/extensions/discounts/discount-rules/create-discount-rule.md ## Permission Scopes: Manage eCommerce - all permissions: SCOPE.DC-ECOM-MEGA.MANAGE-ECOM ## Introduction Creates a new discount rule. --- ## REST API ### Schema ``` Method: createDiscountRule Description: Creates a new discount rule. URL: https://www.wixapis.com/ecom/v1/discount-rules Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: discountRule, discountRule.name, discountRules Method parameters: param name: discountRule | type: DiscountRule | required: true - name: active | type: boolean | description: Whether the discount rule is active. Default: `true` - name: name | type: string | description: Discount rule name. | required: true - name: trigger | type: DiscountTrigger | description: Discount rule trigger. A set of conditions that must be met for the `discounts` to be applied. Not passing a trigger will cause the discount to always apply. - ONE-OF: - name: and | type: And | description: Chain multiple triggers with the `and` operator. - name: triggers | type: array | description: List of triggers to have an "AND" operator between their results. - name: or | type: Or | description: Chain multiple triggers with the `or` operator. - name: triggers | type: array | description: List of triggers to have an "OR" operator between their results. - name: customTrigger | type: Custom | description: Custom trigger. - name: id | type: string | description: Trigger GUID. - name: appId | type: string | description: GUID of the app that created the trigger. - name: subtotalRange | type: SubtotalRange | description: Subtotal trigger range. - name: scopes | type: array | description: Relevant scopes for `SPECIFIC_ITEMS` target type. - ONE-OF: - name: catalogItemFilter | type: CatalogItemFilter | description: Catalog item filter. Must be passed with `type."CATALOG_ITEM"`. - name: catalogAppId | type: string | description: Catalog App GUID. For example, the Wix Stores, Wix Bookings, or 3rd-party [`appId`](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/platform/about-apps-created-by-wix.md). - name: catalogItemIds | type: array | description: GUID of the item within its Wix or 3rd-party catalog. For example, `productId` for Wix Stores. - name: customFilter | type: CustomFilter | description: Custom filter. Must be passed with `type."CATALOG_ITEM"`. - name: appId | type: string | description: Custom filter app GUID, when relevant. - name: params | type: object | description: Custom filter in `{ "key": "value" }` form. For example, an array of `collectionIDs`: `{ ["collectionId": "12345"], ["collectionId": "67890"] }`. - name: id | type: string | description: Scope GUID. - name: type | type: ScopeType | description: Scope type. - enum: - CATALOG_ITEM: Specific catalog items - CUSTOM_FILTER: Specific items by custom filters - name: from | type: string | description: Minimum subtotal price (inclusive). - name: to | type: string | description: Maximum subtotal price (inclusive). - name: itemQuantityRange | type: ItemQuantityRange | description: Item quantity trigger range. - name: scopes | type: array | description: Relevant scopes for `SPECIFIC_ITEMS` target type. - name: from | type: integer | description: Minimum item quantity (inclusive). - name: to | type: integer | description: Maximum item quantity (inclusive). - name: customerEligibility | type: CustomerEligibility | description: Customer Eligibility info - ONE-OF: - name: individualMembersInfo | type: IndividualMembers | description: Information about specific members. - name: memberIds | type: array | description: Eligible member ids. - name: eligibilityType | type: EligibilityType | description: Customer eligibility type. - enum: - INDIVIDUAL_MEMBERS: Only specific customers based on member id. - name: triggerType | type: TriggerType | description: Trigger type. - enum: - AND: Operator used for chaining multiple triggers. Currently 1 `AND` chain operator is supported. - SUBTOTAL_RANGE: Subtotal must be within the specified `subtotalRange` values. - ITEM_QUANTITY_RANGE: Quantity of items in scope must be within specified `itemQuantityRange` values. - CUSTOM: Custom trigger type defined in `customTrigger` object. - OR: Chain multiple triggers with OR operator - CUSTOMER_ELIGIBILITY: Customer eligibility type must be within specified `customerEligibility` values. - name: activeTimeInfo | type: ActiveTimeInfo | description: Time frame in which the discount rule is active. - name: start | type: string | description: Date and time the discount rule is active **from**, in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations) format. - name: end | type: string | description: Date and time the discount rule is active **till**, in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations) format. - name: discounts | type: Discounts | description: List of discounts that are applied when one or more triggers are met. > **Notes:** > > + Currently, only 1 discount can be defined per discount rule. > + A discount rule can be applied on multiple items per cart. > + A discount rule can only be applied once per item. | required: true - name: values | type: array | description: Discounts. - ONE-OF: - name: percentage | type: number | description: Percentage to discount from original price. - name: fixedAmount | type: string | description: Amount to discount from original price. - name: fixedPrice | type: string | description: Fixed price. Line item will be fixed to this price. - name: quantityBased | type: QuantityBased | description: A special price is applied for a specific quantity of items. For example, 3 for $10. - name: configurations | type: array | description: list of discountConfig options. - name: quantity | type: integer | description: The number of items that must be added to the cart to be eligible for the discount (Represents X). - name: price | type: string | description: The DiscountConfig price (Represents Amount). - name: targetType | type: Type | description: Discount target. + `SPECIFIC_ITEMS`: Discount applies to a specific set of items. - enum: - SPECIFIC_ITEMS: Target type is a set of specific items - name: specificItemsInfo | type: SpecificItemsInfo | description: Data related to `SPECIFIC_ITEMS` target type. - name: scopes | type: array | description: All associated scopes for `SPECIFIC_ITEMS` target type. - name: discountType | type: DiscountType | description: Discount type. - enum: - PERCENTAGE: Price is reduced by percentage value. - FIXED_AMOUNT: Price is reduced by fixed amount. - FIXED_PRICE: Price will be set to fixed amount. - QUANTITY_BASED: Quantity based options for Buy X For Amount. - name: tags | type: Tags | description: Tags for this discount rule. - name: privateTags | type: TagList | description: Tags that require an additional permission in order to access them, normally not given to site members or visitors. - name: tagIds | type: array | description: List of tag GUIDs. - name: publicTags | type: TagList | description: Tags that are exposed to anyone who has access to the labeled entity itself, including site members and visitors. Return type: CreateDiscountRuleResponse - name: discountRule | type: DiscountRule | description: Discount rule. - name: id | type: string | description: Discount rule GUID. - name: revision | type: string | description: Revision number, which increments by 1 each time the discount rule is updated. To prevent conflicting changes, the current `revision` must be passed when updating the discount rule. - name: createdDate | type: string | description: Date and time the discount rule was created. - name: updatedDate | type: string | description: Date and time the discount rule was last updated. - name: active | type: boolean | description: Whether the discount rule is active. Default: `true` - name: name | type: string | description: Discount rule name. - name: trigger | type: DiscountTrigger | description: Discount rule trigger. A set of conditions that must be met for the `discounts` to be applied. Not passing a trigger will cause the discount to always apply. - ONE-OF: - name: and | type: And | description: Chain multiple triggers with the `and` operator. - name: triggers | type: array | description: List of triggers to have an "AND" operator between their results. - name: or | type: Or | description: Chain multiple triggers with the `or` operator. - name: triggers | type: array | description: List of triggers to have an "OR" operator between their results. - name: customTrigger | type: Custom | description: Custom trigger. - name: id | type: string | description: Trigger GUID. - name: appId | type: string | description: GUID of the app that created the trigger. - name: subtotalRange | type: SubtotalRange | description: Subtotal trigger range. - name: scopes | type: array | description: Relevant scopes for `SPECIFIC_ITEMS` target type. - ONE-OF: - name: catalogItemFilter | type: CatalogItemFilter | description: Catalog item filter. Must be passed with `type."CATALOG_ITEM"`. - name: catalogAppId | type: string | description: Catalog App GUID. For example, the Wix Stores, Wix Bookings, or 3rd-party [`appId`](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/platform/about-apps-created-by-wix.md). - name: catalogItemIds | type: array | description: GUID of the item within its Wix or 3rd-party catalog. For example, `productId` for Wix Stores. - name: customFilter | type: CustomFilter | description: Custom filter. Must be passed with `type."CATALOG_ITEM"`. - name: appId | type: string | description: Custom filter app GUID, when relevant. - name: params | type: object | description: Custom filter in `{ "key": "value" }` form. For example, an array of `collectionIDs`: `{ ["collectionId": "12345"], ["collectionId": "67890"] }`. - name: id | type: string | description: Scope GUID. - name: type | type: ScopeType | description: Scope type. - enum: - CATALOG_ITEM: Specific catalog items - CUSTOM_FILTER: Specific items by custom filters - name: from | type: string | description: Minimum subtotal price (inclusive). - name: to | type: string | description: Maximum subtotal price (inclusive). - name: itemQuantityRange | type: ItemQuantityRange | description: Item quantity trigger range. - name: scopes | type: array | description: Relevant scopes for `SPECIFIC_ITEMS` target type. - name: from | type: integer | description: Minimum item quantity (inclusive). - name: to | type: integer | description: Maximum item quantity (inclusive). - name: customerEligibility | type: CustomerEligibility | description: Customer Eligibility info - ONE-OF: - name: individualMembersInfo | type: IndividualMembers | description: Information about specific members. - name: memberIds | type: array | description: Eligible member ids. - name: eligibilityType | type: EligibilityType | description: Customer eligibility type. - enum: - INDIVIDUAL_MEMBERS: Only specific customers based on member id. - name: triggerType | type: TriggerType | description: Trigger type. - enum: - AND: Operator used for chaining multiple triggers. Currently 1 `AND` chain operator is supported. - SUBTOTAL_RANGE: Subtotal must be within the specified `subtotalRange` values. - ITEM_QUANTITY_RANGE: Quantity of items in scope must be within specified `itemQuantityRange` values. - CUSTOM: Custom trigger type defined in `customTrigger` object. - OR: Chain multiple triggers with OR operator - CUSTOMER_ELIGIBILITY: Customer eligibility type must be within specified `customerEligibility` values. - name: activeTimeInfo | type: ActiveTimeInfo | description: Time frame in which the discount rule is active. - name: start | type: string | description: Date and time the discount rule is active **from**, in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations) format. - name: end | type: string | description: Date and time the discount rule is active **till**, in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations) format. - name: discounts | type: Discounts | description: List of discounts that are applied when one or more triggers are met. > **Notes:** > > + Currently, only 1 discount can be defined per discount rule. > + A discount rule can be applied on multiple items per cart. > + A discount rule can only be applied once per item. - name: values | type: array | description: Discounts. - ONE-OF: - name: percentage | type: number | description: Percentage to discount from original price. - name: fixedAmount | type: string | description: Amount to discount from original price. - name: fixedPrice | type: string | description: Fixed price. Line item will be fixed to this price. - name: quantityBased | type: QuantityBased | description: A special price is applied for a specific quantity of items. For example, 3 for $10. - name: configurations | type: array | description: list of discountConfig options. - name: id | type: string | description: DiscountConfig GUID. - name: quantity | type: integer | description: The number of items that must be added to the cart to be eligible for the discount (Represents X). - name: price | type: string | description: The DiscountConfig price (Represents Amount). - name: targetType | type: Type | description: Discount target. + `SPECIFIC_ITEMS`: Discount applies to a specific set of items. - enum: - SPECIFIC_ITEMS: Target type is a set of specific items - name: specificItemsInfo | type: SpecificItemsInfo | description: Data related to `SPECIFIC_ITEMS` target type. - name: scopes | type: array | description: All associated scopes for `SPECIFIC_ITEMS` target type. - name: discountType | type: DiscountType | description: Discount type. - enum: - PERCENTAGE: Price is reduced by percentage value. - FIXED_AMOUNT: Price is reduced by fixed amount. - FIXED_PRICE: Price will be set to fixed amount. - QUANTITY_BASED: Quantity based options for Buy X For Amount. - name: status | type: Status | description: Discount rule status. Default: `UNDEFINED` - enum: - LIVE: Rule status is live. - EXPIRED: Rule status is expired, it might have been live in the past. - PENDING: Rule status is pending, it might be live in the future. - name: usageCount | type: integer | description: Number of times the discount rule was used. - name: tags | type: Tags | description: Tags for this discount rule. - name: privateTags | type: TagList | description: Tags that require an additional permission in order to access them, normally not given to site members or visitors. - name: tagIds | type: array | description: List of tag GUIDs. - name: publicTags | type: TagList | description: Tags that are exposed to anyone who has access to the labeled entity itself, including site members and visitors. Possible Errors: HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_SCOPE | Description: Quantity-based discount must target specific items. `specificItemsInfo.scopes.catalogItemFilter.catalogItemIds` can't be empty. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_CUSTOMER_BUY_CONDITION | Description: `buyXGetYInfo.customerBuy.condition` must be defined. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_SETTINGS_SUBJECT_TYPE | Description: `settings.applies_to` must be defined. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_TRIGGER_TYPE | Description: `triggerType` doesn't match the actual trigger. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_SCOPE_TYPE | Description: `scopeType` doesn't match the actual scope. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: OPERATOR_TOO_DEEPLY_NESTED | Description: Trigger nesting exceeded the allowed depth. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_TARGET_TYPE_FIELD | Description: `targetType` can't be set to `UNDEFINED_TARGET`. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_ITEM_QUANTITY_RANGE | Description: `ItemQuantityRange.to` must be greater than `ItemQuantityRange.from`. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_SUBTOTAL_RANGE | Description: `SubtotalRange.to` must be greater than `SubtotalRange.from`. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: MISSING_ITEM_QUANTITY_RANGE | Description: At least one of the following fields must be defined: `ItemQuantityRange.from`, `ItemQuantityRange.to`. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: MISSING_SUBTOTAL_RANGE | Description: At least one of the following fields must be defined: `SubtotalRange.from`, `SubtotalRange.to`. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_DISCOUNT_TYPE | Description: `discountType` must be defined. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_EMPTY_DISCOUNT | Description: Each discount value must be defined. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_ACTIVE_TIME_RANGE | Description: `activeTimeInfo.start` must be before `activeTimeInfo.end`. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: MAX_QUANTITY_BASED_DISCOUNTS_REACHED | Description: Number of quantity-based discounts exceeds the server's limit. HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: MAX_CUSTOM_TRIGGER_APPS_EXCEEDED | Description: Number of distinct custom trigger apps across all discount rules exceeds the server's limit. HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: MAX_DISCOUNT_RULES_REACHED | Description: Number of discount rules exceeds the server's limit. ``` ### Examples ### CreateDiscountRule ```curl ~~~cURL curl -X POST \ 'https://www.wixapis.com/ecom/v1/discount-rules' \ -H 'Content-Type: application/json' \ -H 'Authorization: ' \ --data-binary '{ "discountRule": { "active": true, "name": "15% on all products when buying more than 5 items", "trigger": { "itemQuantityRange": { "scopes": [ { "id": "all_215238eb-22a5-4c36-9e7b-e7c08025e04e", "type": "CATALOG_ITEM", "catalogItemFilter": { "catalogAppId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", "catalogItemIds": [] } } ], "from": 5, "to": null }, "triggerType": "ITEM_QUANTITY_RANGE" }, "discounts": { "values": [ { "targetType": "SPECIFIC_ITEMS", "specificItemsInfo": { "scopes": [ { "id": "all_215238eb-22a5-4c36-9e7b-e7c08025e04e", "type": "CATALOG_ITEM", "catalogItemFilter": { "catalogItemIds": [], "catalogAppId": "215238eb-22a5-4c36-9e7b-e7c08025e04e" } } ] }, "discountType": "PERCENTAGE", "percentage": 15 } ] } } }' ~~~ ``` ### Create Buy X Get Y Discount Rule If the customer purchases a shirt from the shirts category, they'll get a hat from the hats category for free. Discount can be applied up to 2 times (buy 2 hats, get 2 hats). ```curl curl -X POST \ 'https://www.wixapis.com/ecom/v1/discount-rules' \ -H 'Content-Type: application/json' \ -H 'Authorization: ' \ --data-binary '{ "discountRule": { "active": true, "name": "Buy one Shirt, Get a Hat Free!", "discounts": { "values": [ { "targetType": "BUY_X_GET_Y", "fixedPrice": "0", "discountType": "FIXED_PRICE", "buyXGetYInfo": { "customerBuys": { "minimumQuantity": 1, "scopes": [ { "id": "collections_215238eb-22a5-4c36-9e7b-e7c08025e04e", "type": "CUSTOM_FILTER", "customFilter": { "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", "params": { "collectionIds": [ "bfe6699a-256a-47ed-b05e-ddfc0230c297" ] } } } ] }, "customerGets": { "quantity": 1, "scopes": [ { "id": "collections_215238eb-22a5-4c36-9e7b-e7c08025e04e", "type": "CUSTOM_FILTER", "customFilter": { "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", "params": { "collectionIds": [ "088f9822-3455-beba-8b9b-72494f6e6aa7" ] } } } ] }, "limit": 2 } } ] } } }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.discounts.DiscountRuleService.createDiscountRule(discountRule) Description: Creates a new discount rule. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: discountRule, discountRule.name, discountRules Method parameters: param name: discountRule | type: DiscountRule | required: true - name: active | type: boolean | description: Whether the discount rule is active. Default: `true` - name: name | type: string | description: Discount rule name. | required: true - name: trigger | type: DiscountTrigger | description: Discount rule trigger. A set of conditions that must be met for the `discounts` to be applied. Not passing a trigger will cause the discount to always apply. - ONE-OF: - name: and | type: And | description: Chain multiple triggers with the `and` operator. - name: triggers | type: array | description: List of triggers to have an "AND" operator between their results. - name: or | type: Or | description: Chain multiple triggers with the `or` operator. - name: triggers | type: array | description: List of triggers to have an "OR" operator between their results. - name: customTrigger | type: Custom | description: Custom trigger. - name: _id | type: string | description: Trigger GUID. - name: appId | type: string | description: GUID of the app that created the trigger. - name: subtotalRange | type: SubtotalRange | description: Subtotal trigger range. - name: scopes | type: array | description: Relevant scopes for `SPECIFIC_ITEMS` target type. - ONE-OF: - name: catalogItemFilter | type: CatalogItemFilter | description: Catalog item filter. Must be passed with `type."CATALOG_ITEM"`. - name: catalogAppId | type: string | description: Catalog App GUID. For example, the Wix Stores, Wix Bookings, or 3rd-party [`appId`](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/platform/about-apps-created-by-wix.md). - name: catalogItemIds | type: array | description: GUID of the item within its Wix or 3rd-party catalog. For example, `productId` for Wix Stores. - name: customFilter | type: CustomFilter | description: Custom filter. Must be passed with `type."CATALOG_ITEM"`. - name: appId | type: string | description: Custom filter app GUID, when relevant. - name: params | type: object | description: Custom filter in `{ "key": "value" }` form. For example, an array of `collectionIDs`: `{ ["collectionId": "12345"], ["collectionId": "67890"] }`. - name: _id | type: string | description: Scope GUID. - name: type | type: ScopeType | description: Scope type. - enum: - CATALOG_ITEM: Specific catalog items - CUSTOM_FILTER: Specific items by custom filters - name: from | type: string | description: Minimum subtotal price (inclusive). - name: to | type: string | description: Maximum subtotal price (inclusive). - name: itemQuantityRange | type: ItemQuantityRange | description: Item quantity trigger range. - name: scopes | type: array | description: Relevant scopes for `SPECIFIC_ITEMS` target type. - name: from | type: integer | description: Minimum item quantity (inclusive). - name: to | type: integer | description: Maximum item quantity (inclusive). - name: customerEligibility | type: CustomerEligibility | description: Customer Eligibility info - ONE-OF: - name: individualMembersInfo | type: IndividualMembers | description: Information about specific members. - name: memberIds | type: array | description: Eligible member ids. - name: eligibilityType | type: EligibilityType | description: Customer eligibility type. - enum: - INDIVIDUAL_MEMBERS: Only specific customers based on member id. - name: triggerType | type: TriggerType | description: Trigger type. - enum: - AND: Operator used for chaining multiple triggers. Currently 1 `AND` chain operator is supported. - SUBTOTAL_RANGE: Subtotal must be within the specified `subtotalRange` values. - ITEM_QUANTITY_RANGE: Quantity of items in scope must be within specified `itemQuantityRange` values. - CUSTOM: Custom trigger type defined in `customTrigger` object. - OR: Chain multiple triggers with OR operator - CUSTOMER_ELIGIBILITY: Customer eligibility type must be within specified `customerEligibility` values. - name: activeTimeInfo | type: ActiveTimeInfo | description: Time frame in which the discount rule is active. - name: start | type: Date | description: Date and time the discount rule is active **from**, in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations) format. - name: end | type: Date | description: Date and time the discount rule is active **till**, in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations) format. - name: discounts | type: Discounts | description: List of discounts that are applied when one or more triggers are met. > **Notes:** > > + Currently, only 1 discount can be defined per discount rule. > + A discount rule can be applied on multiple items per cart. > + A discount rule can only be applied once per item. | required: true - name: values | type: array | description: Discounts. - ONE-OF: - name: percentage | type: number | description: Percentage to discount from original price. - name: fixedAmount | type: string | description: Amount to discount from original price. - name: fixedPrice | type: string | description: Fixed price. Line item will be fixed to this price. - name: quantityBased | type: QuantityBased | description: A special price is applied for a specific quantity of items. For example, 3 for $10. - name: configurations | type: array | description: list of discountConfig options. - name: quantity | type: integer | description: The number of items that must be added to the cart to be eligible for the discount (Represents X). - name: price | type: string | description: The DiscountConfig price (Represents Amount). - name: targetType | type: Type | description: Discount target. + `SPECIFIC_ITEMS`: Discount applies to a specific set of items. - enum: - SPECIFIC_ITEMS: Target type is a set of specific items - name: specificItemsInfo | type: SpecificItemsInfo | description: Data related to `SPECIFIC_ITEMS` target type. - name: scopes | type: array | description: All associated scopes for `SPECIFIC_ITEMS` target type. - name: discountType | type: DiscountType | description: Discount type. - enum: - PERCENTAGE: Price is reduced by percentage value. - FIXED_AMOUNT: Price is reduced by fixed amount. - FIXED_PRICE: Price will be set to fixed amount. - QUANTITY_BASED: Quantity based options for Buy X For Amount. - name: tags | type: Tags | description: Tags for this discount rule. - name: privateTags | type: TagList | description: Tags that require an additional permission in order to access them, normally not given to site members or visitors. - name: tagIds | type: array | description: List of tag GUIDs. - name: publicTags | type: TagList | description: Tags that are exposed to anyone who has access to the labeled entity itself, including site members and visitors. Return type: PROMISE - name: _id | type: string | description: Discount rule GUID. - name: revision | type: string | description: Revision number, which increments by 1 each time the discount rule is updated. To prevent conflicting changes, the current `revision` must be passed when updating the discount rule. - name: _createdDate | type: Date | description: Date and time the discount rule was created. - name: _updatedDate | type: Date | description: Date and time the discount rule was last updated. - name: active | type: boolean | description: Whether the discount rule is active. Default: `true` - name: name | type: string | description: Discount rule name. - name: trigger | type: DiscountTrigger | description: Discount rule trigger. A set of conditions that must be met for the `discounts` to be applied. Not passing a trigger will cause the discount to always apply. - ONE-OF: - name: and | type: And | description: Chain multiple triggers with the `and` operator. - name: triggers | type: array | description: List of triggers to have an "AND" operator between their results. - name: or | type: Or | description: Chain multiple triggers with the `or` operator. - name: triggers | type: array | description: List of triggers to have an "OR" operator between their results. - name: customTrigger | type: Custom | description: Custom trigger. - name: _id | type: string | description: Trigger GUID. - name: appId | type: string | description: GUID of the app that created the trigger. - name: subtotalRange | type: SubtotalRange | description: Subtotal trigger range. - name: scopes | type: array | description: Relevant scopes for `SPECIFIC_ITEMS` target type. - ONE-OF: - name: catalogItemFilter | type: CatalogItemFilter | description: Catalog item filter. Must be passed with `type."CATALOG_ITEM"`. - name: catalogAppId | type: string | description: Catalog App GUID. For example, the Wix Stores, Wix Bookings, or 3rd-party [`appId`](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/platform/about-apps-created-by-wix.md). - name: catalogItemIds | type: array | description: GUID of the item within its Wix or 3rd-party catalog. For example, `productId` for Wix Stores. - name: customFilter | type: CustomFilter | description: Custom filter. Must be passed with `type."CATALOG_ITEM"`. - name: appId | type: string | description: Custom filter app GUID, when relevant. - name: params | type: object | description: Custom filter in `{ "key": "value" }` form. For example, an array of `collectionIDs`: `{ ["collectionId": "12345"], ["collectionId": "67890"] }`. - name: _id | type: string | description: Scope GUID. - name: type | type: ScopeType | description: Scope type. - enum: - CATALOG_ITEM: Specific catalog items - CUSTOM_FILTER: Specific items by custom filters - name: from | type: string | description: Minimum subtotal price (inclusive). - name: to | type: string | description: Maximum subtotal price (inclusive). - name: itemQuantityRange | type: ItemQuantityRange | description: Item quantity trigger range. - name: scopes | type: array | description: Relevant scopes for `SPECIFIC_ITEMS` target type. - name: from | type: integer | description: Minimum item quantity (inclusive). - name: to | type: integer | description: Maximum item quantity (inclusive). - name: customerEligibility | type: CustomerEligibility | description: Customer Eligibility info - ONE-OF: - name: individualMembersInfo | type: IndividualMembers | description: Information about specific members. - name: memberIds | type: array | description: Eligible member ids. - name: eligibilityType | type: EligibilityType | description: Customer eligibility type. - enum: - INDIVIDUAL_MEMBERS: Only specific customers based on member id. - name: triggerType | type: TriggerType | description: Trigger type. - enum: - AND: Operator used for chaining multiple triggers. Currently 1 `AND` chain operator is supported. - SUBTOTAL_RANGE: Subtotal must be within the specified `subtotalRange` values. - ITEM_QUANTITY_RANGE: Quantity of items in scope must be within specified `itemQuantityRange` values. - CUSTOM: Custom trigger type defined in `customTrigger` object. - OR: Chain multiple triggers with OR operator - CUSTOMER_ELIGIBILITY: Customer eligibility type must be within specified `customerEligibility` values. - name: activeTimeInfo | type: ActiveTimeInfo | description: Time frame in which the discount rule is active. - name: start | type: Date | description: Date and time the discount rule is active **from**, in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations) format. - name: end | type: Date | description: Date and time the discount rule is active **till**, in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations) format. - name: discounts | type: Discounts | description: List of discounts that are applied when one or more triggers are met. > **Notes:** > > + Currently, only 1 discount can be defined per discount rule. > + A discount rule can be applied on multiple items per cart. > + A discount rule can only be applied once per item. - name: values | type: array | description: Discounts. - ONE-OF: - name: percentage | type: number | description: Percentage to discount from original price. - name: fixedAmount | type: string | description: Amount to discount from original price. - name: fixedPrice | type: string | description: Fixed price. Line item will be fixed to this price. - name: quantityBased | type: QuantityBased | description: A special price is applied for a specific quantity of items. For example, 3 for $10. - name: configurations | type: array | description: list of discountConfig options. - name: _id | type: string | description: DiscountConfig GUID. - name: quantity | type: integer | description: The number of items that must be added to the cart to be eligible for the discount (Represents X). - name: price | type: string | description: The DiscountConfig price (Represents Amount). - name: targetType | type: Type | description: Discount target. + `SPECIFIC_ITEMS`: Discount applies to a specific set of items. - enum: - SPECIFIC_ITEMS: Target type is a set of specific items - name: specificItemsInfo | type: SpecificItemsInfo | description: Data related to `SPECIFIC_ITEMS` target type. - name: scopes | type: array | description: All associated scopes for `SPECIFIC_ITEMS` target type. - name: discountType | type: DiscountType | description: Discount type. - enum: - PERCENTAGE: Price is reduced by percentage value. - FIXED_AMOUNT: Price is reduced by fixed amount. - FIXED_PRICE: Price will be set to fixed amount. - QUANTITY_BASED: Quantity based options for Buy X For Amount. - name: status | type: Status | description: Discount rule status. Default: `UNDEFINED` - enum: - LIVE: Rule status is live. - EXPIRED: Rule status is expired, it might have been live in the past. - PENDING: Rule status is pending, it might be live in the future. - name: usageCount | type: integer | description: Number of times the discount rule was used. - name: tags | type: Tags | description: Tags for this discount rule. - name: privateTags | type: TagList | description: Tags that require an additional permission in order to access them, normally not given to site members or visitors. - name: tagIds | type: array | description: List of tag GUIDs. - name: publicTags | type: TagList | description: Tags that are exposed to anyone who has access to the labeled entity itself, including site members and visitors. Possible Errors: HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_SCOPE | Description: Quantity-based discount must target specific items. `specificItemsInfo.scopes.catalogItemFilter.catalogItemIds` can't be empty. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_CUSTOMER_BUY_CONDITION | Description: `buyXGetYInfo.customerBuy.condition` must be defined. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_SETTINGS_SUBJECT_TYPE | Description: `settings.applies_to` must be defined. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_TRIGGER_TYPE | Description: `triggerType` doesn't match the actual trigger. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_SCOPE_TYPE | Description: `scopeType` doesn't match the actual scope. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: OPERATOR_TOO_DEEPLY_NESTED | Description: Trigger nesting exceeded the allowed depth. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_TARGET_TYPE_FIELD | Description: `targetType` can't be set to `UNDEFINED_TARGET`. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_ITEM_QUANTITY_RANGE | Description: `ItemQuantityRange.to` must be greater than `ItemQuantityRange.from`. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_SUBTOTAL_RANGE | Description: `SubtotalRange.to` must be greater than `SubtotalRange.from`. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: MISSING_ITEM_QUANTITY_RANGE | Description: At least one of the following fields must be defined: `ItemQuantityRange.from`, `ItemQuantityRange.to`. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: MISSING_SUBTOTAL_RANGE | Description: At least one of the following fields must be defined: `SubtotalRange.from`, `SubtotalRange.to`. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_DISCOUNT_TYPE | Description: `discountType` must be defined. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_EMPTY_DISCOUNT | Description: Each discount value must be defined. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_ACTIVE_TIME_RANGE | Description: `activeTimeInfo.start` must be before `activeTimeInfo.end`. HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: MAX_QUANTITY_BASED_DISCOUNTS_REACHED | Description: Number of quantity-based discounts exceeds the server's limit. HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: MAX_CUSTOM_TRIGGER_APPS_EXCEEDED | Description: Number of distinct custom trigger apps across all discount rules exceeds the server's limit. HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: MAX_DISCOUNT_RULES_REACHED | Description: Number of discount rules exceeds the server's limit. ``` ### Examples ### createDiscountRule ```javascript import { discountRules } from '@wix/ecom'; async function createDiscountRule(discountRule) { const response = await discountRules.createDiscountRule(discountRule); }; ``` ### createDiscountRule (with elevated permissions) ```javascript import { discountRules } from '@wix/ecom'; import { auth } from '@wix/essentials'; async function myCreateDiscountRuleMethod(discountRule) { const elevatedCreateDiscountRule = auth.elevate(discountRules.createDiscountRule); const response = await elevatedCreateDiscountRule(discountRule); } ``` ### createDiscountRule (self-hosted) Self-hosted 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 { discountRules } from '@wix/ecom'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { discountRules }, // Include the auth strategy and host as relevant }); async function createDiscountRule(discountRule) { const response = await myWixClient.discountRules.createDiscountRule(discountRule); }; ``` ---