> 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 # Package: loyaltyProgramManagement # Namespace: earningRules # Webhook link: https://dev.wix.com/docs/api-reference/crm/loyalty-program/loyalty-program-management/earning-rules/loyalty-earning-rule-updated.md ## Introduction Triggered when an earning rule is updated. --- ## REST API ### Schema ``` Webhook: Loyalty Earning Rule Updated Description: Triggered when an earning 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: LoyaltyEarningRule | description: The entity after the update. - ONE-OF: - name: fixedAmount | type: FixedAmount | description: Fixed amount of points awarded for each qualifying activity. - name: configs | type: array | description: Fixed amount configurations for each tier. - name: tierId | type: string | description: Tier GUID. If empty, the base tier is used. See the Tiers API for more information. - name: points | type: integer | description: Number of points to award. - name: conversionRate | type: ConversionRate | description: Points awarded based on a conversion rate formula: `(amount spent) / (money_amount * points)`. - name: configs | type: array | description: Conversion rate configurations for each tier. Points are awarded proportionally to the amount spent. Formula: `(amount spent) / (money_amount * points)`. - name: tierId | type: string | description: Tier GUID. If empty, the base tier is used. See the Tiers API for more information. - name: moneyAmount | type: integer | description: The amount of money used as a reference for point calculation. Points are awarded proportionally to the amount spent. For example, if set to 10, 1 point is awarded for every 10 units of currency spent (assuming `points` is set to 1). Formula for points is: `(amount spent) / (money_amount * points)`. - name: points | type: integer | description: Points given for the specified `money_amount`. Works in conjunction with `money_amount` to define the earning rule. For example: If `money_amount` is 20 and `points` is 10: - Spending 10 units of currency earns 5 points - Spending 20 units of currency earns 10 points - Spending 30 units of currency earns 15 points - name: field | type: string | description: Specifies which field in the Wix automations trigger payload [REST](https://dev.wix.com/docs/rest/business-management/automations/introduction.md#how-do-automations-work)|[SDK](https://dev.wix.com/docs/sdk/backend-modules/automations/triggered-events/reporting-and-canceling-events.md) to use for calculating points in conversion rate rules. For example, if set to "priceSummary.totalAmount", the rule uses the total order amount to calculate loyalty points to be awarded. This field is only applicable for automated earning rules. - name: id | type: string | description: Loyalty earning rule GUID. - name: sourceAppId | type: string | description: GUID of the app managing the earning rule. Can be a loyalty app GUID or a Wix automations app GUID. - name: triggerAppId | type: string | description: GUID of the app that triggers point assignment. Examples: Wix Stores, Wix Bookings, Wix Events. - name: triggerActivityType | type: string | description: Type of activity that triggers point assignment. For example, `wix-restaurants/orderSubmitted` or `birthday`. - name: title | type: string | description: Name of the earning rule. - name: status | type: Status | description: Current status of the earning rule. - enum: - UNKNOWN: Status is unknown or not specified. - ACTIVE: Earning rule is active and can assign points. - PAUSED: Earning rule is paused and can't assign points. - name: revision | type: string | description: Revision number, incremented by 1 each time the earning rule is updated. Pass the latest `revision` when updating to prevent conflicting changes. - name: createdDate | type: string | description: Date and time the earning rule was created. - name: updatedDate | type: string | description: Date and time the earning rule was last updated. - name: metadata | type: Metadata | description: Additional metadata about the earning rule. - name: canBeDeleted | type: boolean | description: Whether the earning rule can be deleted. - name: triggerFilters | type: array | description: Trigger filters parsed from automation configuration. Only present for automation-based rules with filters. - name: fieldKey | type: string | description: Key identifying the field in the trigger payload (e.g., "service_id", "eventId", "programId"). - name: values | type: array | description: Parsed entity GUIDs that the filter matches against. ``` ### Examples ```curl { "id": "79e98s2a-d8j4-4a3b-a62f-7393757bab84", "entityFqdn": "wix.loyalty.v1.loyalty_earning_rule", "slug": "updated", "entityId": "5bf5cb44-87rt-4933-1234-1d8423636a74", "updatedEvent": { "currentEntity": { "id": "b690f925-8527-4d5e-b358-4b0adcb275b5", "sourceAppId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df", "triggerAppId": "1380b703-ce81-ff05-f115-39571d94dfcd", "triggerActivityType": "stores/OrderPaid", "title": "Purchase a product", "conversionRate": { "moneyAmount": 1, "points": 20, "configs": [ { "moneyAmount": 1, "points": 20 } ] }, "status": "ACTIVE", "revision": "1", "createdDate": "2024-09-16T12:06:39.294Z", "updatedDate": "2024-09-16T12:06:39.294Z", "metadata": { "canBeDeleted": true } } }, "eventTime": "2023-09-11T14:58:22.481838Z", "triggeredByAnonymizeRequest": false, "entityEventSequence": "1" } ``` --- ## JavaScript SDK ### Schema ``` Webhook: onLoyaltyEarningRuleUpdated Description: Triggered when an earning rule is updated. Payload: LoyaltyEarningRuleUpdatedEnvelope - name: entity | type: LoyaltyEarningRule | description: none - ONE-OF: - name: fixedAmount | type: FixedAmount | description: Fixed amount of points awarded for each qualifying activity. - name: configs | type: array | description: Fixed amount configurations for each tier. - name: tierId | type: string | description: Tier GUID. If empty, the base tier is used. See the Tiers API for more information. - name: points | type: integer | description: Number of points to award. - name: conversionRate | type: ConversionRate | description: Points awarded based on a conversion rate formula: `(amount spent) / (money_amount * points)`. - name: configs | type: array | description: Conversion rate configurations for each tier. Points are awarded proportionally to the amount spent. Formula: `(amount spent) / (money_amount * points)`. - name: tierId | type: string | description: Tier GUID. If empty, the base tier is used. See the Tiers API for more information. - name: moneyAmount | type: integer | description: The amount of money used as a reference for point calculation. Points are awarded proportionally to the amount spent. For example, if set to 10, 1 point is awarded for every 10 units of currency spent (assuming `points` is set to 1). Formula for points is: `(amount spent) / (money_amount * points)`. - name: points | type: integer | description: Points given for the specified `money_amount`. Works in conjunction with `money_amount` to define the earning rule. For example: If `money_amount` is 20 and `points` is 10: - Spending 10 units of currency earns 5 points - Spending 20 units of currency earns 10 points - Spending 30 units of currency earns 15 points - name: field | type: string | description: Specifies which field in the Wix automations trigger payload [REST](https://dev.wix.com/docs/rest/business-management/automations/introduction.md#how-do-automations-work)|[SDK](https://dev.wix.com/docs/sdk/backend-modules/automations/triggered-events/reporting-and-canceling-events.md) to use for calculating points in conversion rate rules. For example, if set to "priceSummary.totalAmount", the rule uses the total order amount to calculate loyalty points to be awarded. This field is only applicable for automated earning rules. - name: _id | type: string | description: Loyalty earning rule GUID. - name: sourceAppId | type: string | description: GUID of the app managing the earning rule. Can be a loyalty app GUID or a Wix automations app GUID. - name: triggerAppId | type: string | description: GUID of the app that triggers point assignment. Examples: Wix Stores, Wix Bookings, Wix Events. - name: triggerActivityType | type: string | description: Type of activity that triggers point assignment. For example, `wix-restaurants/orderSubmitted` or `birthday`. - name: title | type: string | description: Name of the earning rule. - name: status | type: Status | description: Current status of the earning rule. - enum: - UNKNOWN: Status is unknown or not specified. - ACTIVE: Earning rule is active and can assign points. - PAUSED: Earning rule is paused and can't assign points. - name: revision | type: string | description: Revision number, incremented by 1 each time the earning rule is updated. Pass the latest `revision` when updating to prevent conflicting changes. - name: _createdDate | type: Date | description: Date and time the earning rule was created. - name: _updatedDate | type: Date | description: Date and time the earning rule was last updated. - name: metadata | type: Metadata | description: Additional metadata about the earning rule. - name: canBeDeleted | type: boolean | description: Whether the earning rule can be deleted. - name: triggerFilters | type: array | description: Trigger filters parsed from automation configuration. Only present for automation-based rules with filters. - name: fieldKey | type: string | description: Key identifying the field in the trigger payload (e.g., "service_id", "eventId", "programId"). - name: values | type: array | description: Parsed entity GUIDs that the filter matches against. - 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 { earningRules } from '@wix/loyalty'; earningRules.onLoyaltyEarningRuleUpdated((event) => { // handle your event here }); ``` ```javascript import { createClient, AppStrategy } from '@wix/sdk'; import { earningRules } from '@wix/loyalty'; const wixClient = createClient({ auth: AppStrategy({ appId: 'MY-APP-ID', publicKey: 'YOUR_APP_PUBLIC_KEY', }), modules: { earningRules, }, }); wixClient.earningRules.onLoyaltyEarningRuleUpdated((event) => { // handle your event here }); ``` ---