> 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

# Package: discounts

# Namespace: discountRules

# Webhook link: https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/extensions/discounts/discount-rules/discount-rule-updated.md

# Webhook Permissions Scopes IDs:
Read eCommerce - all read permissions: SCOPE.DC-ECOM-MEGA.READ-ECOM

## Introduction

Triggered when a discount rule is updated.

---

## REST API

### Schema

```
Webhook: Discount Rule Updated
Description: Triggered when a discount rule is updated.
Event body:
 - name: id | type: string | description: Unique event ID. Allows clients to ignore duplicate events.
 - name: entityFqdn | type: string | description: Fully qualified domain name of the entity associated with the event.
 - name: slug | type: string | description: Event name.
 - name: entityId | type: string | description: ID of the entity associated with the event.
 - name: eventTime | type: string (date-time) | description: Event timestamp.
 - name: triggeredByAnonymizeRequest | type: boolean | description: Whether the event was triggered as a result of a privacy regulation application such as GDPR.
 - name: originatedFrom | type: string | description: If present, indicates the action that triggered the event.
 - name: updatedEvent | type: object | description: Updated event details.
    - name: currentEntity | type: DiscountRule | description: The entity after the update.
        - 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 turned on. A discount rule applies only when `active` is `true` and, when `activeTimeInfo` is set, the current time is in its range.  `active` doesn't affect `status`. A discount rule with `active` set to `false` can still have the status `LIVE`.  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<DiscountTrigger> | 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<DiscountTrigger> | 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<Scope> | 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<string> | 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."CUSTOM_FILTER"`.
                          - name: appId | type: string | description: Custom filter app GUID, when relevant.
                          - name: params | type: object | description: Custom filter parameters in `{ "key": "value" }` form. The keys depend on the scope. For example, for the Wix Stores collections scope: `{ "collectionIds": ["4d2f6b1a-8c3e-4f5a-9b7d-2e1c0a9f8b6d", "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d"] }`.  `collectionIds` takes collection GUIDs, not collection names. On sites that use Catalog V3, specify category GUIDs.
                    - name: id | type: string | description: GUID of a scope that the app providing the items defines. For example, `all_215238eb-22a5-4c36-9e7b-e7c08025e04e` for all Wix Stores products, or `collections_215238eb-22a5-4c36-9e7b-e7c08025e04e` for specific Wix Stores collections.  Use an existing scope GUID, not a name of your own. For a custom filter, the GUID is passed to the app that provides the scope to find the items that the discount applies to.
                    - 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<Scope> | 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<string> | 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<Discount> | 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<DiscountConfig> | 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<Scope> | 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.  `status` doesn't reflect `active`. To find the discount rules that apply now, check both `active` and `status`.
           - 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<string> | 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.
    - name: modifiedFields | type: Map<string,Value> | description: Fields that were updated and their values before the update.

```

### Examples


```curl
{
  "entityId": "18b3a857-131e-47b1-8748-3c4d362511f3",
  "entityEventSequence": "2",
  "slug": "updated",
  "id": "656ddf67-99fc-44ab-b3b1-6f99623328fd",
  "entityFqdn": "wix.ecom.discounts.v1.discount_rule",
  "updatedEvent": {
    "currentEntity": {
      "usageCount": 0,
      "name": "New discount name",
      "revision": "2",
      "id": "18b3a857-131e-47b1-8748-3c4d362511f3",
      "status": "LIVE",
      "discounts": {
        "values": [
          {
            "targetType": "SPECIFIC_ITEMS",
            "specificItemsInfo": {
              "scopes": [
                {
                  "id": "all_215238eb-22a5-4c36-9e7b-e7c08025e04e",
                  "type": "CATALOG_ITEM",
                  "catalogItemFilter": {
                    "catalogAppId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",
                    "catalogItemIds": []
                  }
                }
              ]
            },
            "percentage": 15,
            "discountType": "PERCENTAGE"
          }
        ]
      },
      "offer": "15% off\nAll products",
      "updatedDate": "2023-06-28T12:51:41.482Z",
      "createdDate": "2023-06-28T12:43:22.739Z",
      "active": true,
      "trigger": {
        "itemQuantityRange": {
          "scopes": [
            {
              "id": "all_215238eb-22a5-4c36-9e7b-e7c08025e04e",
              "type": "CATALOG_ITEM",
              "catalogItemFilter": {
                "catalogAppId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",
                "catalogItemIds": []
              }
            }
          ],
          "from": 5
        },
        "triggerType": "ITEM_QUANTITY_RANGE"
      }
    }
  },
  "eventTime": "2023-06-28T12:51:41.489714Z",
  "triggeredByAnonymizeRequest": false
}
```

---

## JavaScript SDK

### Schema

```
Webhook: onDiscountRuleUpdated
Description: Triggered when a discount rule is updated.
Payload: DiscountRuleUpdatedEnvelope
  - name: entity | type: DiscountRule | description: none
     - 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 turned on. A discount rule applies only when `active` is `true` and, when `activeTimeInfo` is set, the current time is in its range.  `active` doesn't affect `status`. A discount rule with `active` set to `false` can still have the status `LIVE`.  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<DiscountTrigger> | 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<DiscountTrigger> | 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<Scope> | 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<string> | 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."CUSTOM_FILTER"`.
                       - name: appId | type: string | description: Custom filter app GUID, when relevant.
                       - name: params | type: object | description: Custom filter parameters in `{ "key": "value" }` form. The keys depend on the scope. For example, for the Wix Stores collections scope: `{ "collectionIds": ["4d2f6b1a-8c3e-4f5a-9b7d-2e1c0a9f8b6d", "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d"] }`.  `collectionIds` takes collection GUIDs, not collection names. On sites that use Catalog V3, specify category GUIDs.
                 - name: _id | type: string | description: GUID of a scope that the app providing the items defines. For example, `all_215238eb-22a5-4c36-9e7b-e7c08025e04e` for all Wix Stores products, or `collections_215238eb-22a5-4c36-9e7b-e7c08025e04e` for specific Wix Stores collections.  Use an existing scope GUID, not a name of your own. For a custom filter, the GUID is passed to the app that provides the scope to find the items that the discount applies to.
                 - 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<Scope> | 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<string> | 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<Discount> | 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<DiscountConfig> | 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<Scope> | 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.  `status` doesn't reflect `active`. To find the discount rules that apply now, check both `active` and `status`.
         - 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<string> | 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.
  - name: modifiedFields | type: object | description: Fields that were updated and their values before the update.
  - name: metadata | type: EventMetadata | description: none
     - name: instanceId | type: string | description: App instance GUID.
     - name: eventType | type: string | description: Event type.
     - name: identity | type: IdentificationData | description: The identification type and identity data.
        - ONE-OF:
           - name: anonymousVisitorId | type: string | description: GUID of a site visitor that has not logged in to the site.
           - name: memberId | type: string | description: GUID of a site visitor that has logged in to the site.
           - name: wixUserId | type: string | description: GUID of a Wix user (site owner, contributor, etc.).
           - name: appId | type: string | description: GUID of an app.
        - name: identityType | type: WebhookIdentityType | description: 
             - enum: UNKNOWN, ANONYMOUS_VISITOR, MEMBER, WIX_USER, APP
     - name: accountInfo | type: AccountInfo | description: Details related to the account
        - name: accountId | type: string | description: GUID of the Wix account associated with the event.
        - name: parentAccountId | type: string | description: GUID of the parent Wix account. Only included when accountId belongs to a child account.
        - name: siteId | type: string | description: GUID of the Wix site associated with the event. Only included when the event is tied to a specific site.
     - name: _id | type: string | description: Event GUID. With this GUID you can easily spot duplicated events and ignore them.
     - name: entityFqdn | type: string | description: Fully Qualified Domain Name of an entity. This is a unique identifier assigned to the API main business entities. For example, `wix.stores.catalog.product`, `wix.bookings.session`, `wix.payments.transaction`.
     - name: slug | type: string | description: Event action name, placed at the top level to make it easier for users to dispatch messages. For example: `created`/`updated`/`deleted`/`started`/`completed`/`email_opened`.
     - name: entityId | type: string | description: GUID of the entity associated with the event.
     - name: eventTime | type: Date | description: Event timestamp in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) format and UTC time. For example, `2020-04-26T13:57:50.699Z`.
     - name: triggeredByAnonymizeRequest | type: boolean | description: Whether the event was triggered as a result of a privacy regulation application (for example, GDPR).
     - name: originatedFrom | type: string | description: If present, indicates the action that triggered the event.
     - name: entityEventSequence | type: string | description: A sequence number that indicates the order of updates to an entity. For example, if an entity was updated at `16:00` and then again at `16:01`, the second update will always have a higher sequence number. You can use this number to make sure you're handling updates in the right order. Just save the latest sequence number on your end and compare it to the one in each new message. If the new message has an older (lower) number, you can safely ignore it.

```

### Examples


```javascript
import { discountRules } from '@wix/ecom';

discountRules.onDiscountRuleUpdated((event) => {
    // handle your event here
});
```


```javascript
import { createClient, AppStrategy } from '@wix/sdk';
import { discountRules } from '@wix/ecom';

const wixClient = createClient({
  auth: AppStrategy({
    appId: 'MY-APP-ID',
    publicKey: 'YOUR_APP_PUBLIC_KEY',
  }),
  modules: {
      discountRules,
    },
});

wixClient.discountRules.onDiscountRuleUpdated((event) => {
    // handle your event here
});
```

---