> 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: rewards # Namespace: coupons # Webhook link: https://dev.wix.com/docs/api-reference/crm/loyalty-program/rewards/coupons/coupon-created.md ## Introduction Triggered when a loyalty coupon is created. --- ## REST API ### Schema ``` Webhook: Coupon Created Description: Triggered when a loyalty coupon is created. 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: createdEvent | type: object | description: Created event details. - name: entity | type: LoyaltyCoupon | description: The created entity. - name: id | type: string | description: Loyalty coupon GUID. - name: accountId | type: string | description: Loyalty [account GUID](https://dev.wix.com/docs/rest/crm/loyalty-program/accounts/account-object.md) of the customer that redeemed points for a coupon. - name: memberId | type: string | description: Member GUID of the customer that redeemed points for a coupon. See the Members API for more information. - name: transactionId | type: string | description: [Transaction GUID](https://dev.wix.com/docs/rest/crm/loyalty-program/transactions/loyalty-transaction-object.md) for the transaction that created a coupon. - name: couponReference | type: CouponReference | description: Reference coupon information for the corresponding [coupon](https://dev.wix.com/docs/rest/business-management/marketing/coupons/coupons/coupon-object.md) that is created along with the loyalty coupon. - name: couponId | type: string | description: Coupon GUID. - name: code | type: string | description: Coupon code. Unique code entered by a customer to apply the coupon. - name: name | type: string | description: Name of coupon. - name: specification | type: Specification | description: The information to use when creating the coupon. - ONE-OF: - name: moneyOffAmount | type: number | description: Fixed price discount. - 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` on a site. - name: fixedPriceAmount | type: number | description: Specific sale price. Currently only supported for coupons with a `stores` `namespace`. - name: buyXGetY | type: BuyXGetY | description: Free products when making a purchase. `buyXGetY` is an object that specifies `x` and `y` in the following scenario: if a visitor purchases x number of products, they receive y number of products for free. C urrently only supported for coupons with a `stores` `namespace`. - 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. - ONE-OF: - name: scope | type: Scope | description: Scope of the coupon. When no scope is defined, the coupon applies to all items in all `namespaces` in the site. - name: name | type: string | description: Group within a `namespace` for which the coupon is applicable. If no group is specified, the coupon applies to all items in the namespace. `group` is required in some namespaces. See [Scope Values](https://dev.wix.com/api/rest/coupons/coupons/valid-scope-values) for a list of currently supported groups for each namespace. - name: entityId | type: string | description: GUID of the specific entity in the group for which the coupon is applicable. If no `entityId` is specified, the coupon applies to all entities in the group. In some cases when a group is specified, an `entityId` is required. See [Scope Values](https://dev.wix.com/api/rest/coupons/coupons/valid-scope-values) for a list of currently supported entities for each namespace and group. - name: namespace | type: string | description: Wix application for which the coupon is applicable. One of the following: + `"stores"` + `"bookings"` + `"events"` + `"pricingPlans"` - name: minimumSubtotal | type: number | description: The coupon is only applicable when the order subtotal is over this amount. - name: name | type: string | description: Name of coupon. - name: type | type: Type | description: - enum: UNKNOWN, MONEY_OFF_AMOUNT, PERCENT_OFF_RATE, FREE_SHIPPING, FIXED_PRICE_AMOUNT, BUY_X_GET_Y - name: limitedToOneItem | type: boolean | description: Whether the coupon is limited to 1 discount per order. If true and a customer pays for multiple items that the coupon applies to, only the lowest priced item is discounted. Coupons with a `bookings` `namespace` are always limited to 1 item. - name: appliesToSubscriptions | type: boolean | description: Whether the coupon also applies to subscriptions. - name: discountedCycleCount | type: integer | description: Specifies the amount of cycles to apply the discount to for a subscription item. Can only be set when `appliesToSubscriptions` is `TRUE` and `specification.scope.namespace` is `pricingPlans`. If `discountedCycleCount` is empty, the coupon applies to all available cycles. Min: `1` Max: `999` - name: deleted | type: boolean | description: Whether the referenced coupon was deleted. - name: status | type: Status | description: Loyalty coupon status. This status relates to the corresponding coupon that is created at the same time as the loyalty coupon and is included in `couponReference`. - enum: - UNKNOWN: Unknown status. - PENDING: The reference coupon was created but the loyalty points have not been redeemed yet. - ACTIVE: The reference coupon is active and available to the customer. - APPLIED: The reference coupon was applied and is no longer available for use. - FAILED: The reference coupon was created but something went wrong when redeeming points from the loyalty account. - ARCHIVED: The reference coupon was deleted. - name: rewardName | type: string | description: Name of reward that was redeemed to create this coupon. - name: revision | type: string | description: Revision number, which increments by 1 each time the loyalty coupon is updated. To prevent conflicting changes, the current `revision` must be passed when updating the loyalty coupon. - name: createdDate | type: string | description: Date and time the loyalty coupon was created. - name: updatedDate | type: string | description: Date and time the loyalty coupon was last updated. - name: refundable | type: boolean | description: Whether the loyalty coupon was created in a "refundable workflow" i.e. checkout-exchange, and therefore can be deleted in the background. Refundable coupons should not be visible to customers in the UI. ``` --- ## JavaScript SDK ### Schema ``` Webhook: onCouponCreated Description: Triggered when a loyalty coupon is created. Payload: CouponCreatedEnvelope - name: entity | type: LoyaltyCoupon | description: none - name: _id | type: string | description: Loyalty coupon GUID. - name: accountId | type: string | description: Loyalty [account GUID](https://dev.wix.com/docs/rest/crm/loyalty-program/accounts/account-object.md) of the customer that redeemed points for a coupon. - name: memberId | type: string | description: Member GUID of the customer that redeemed points for a coupon. See the Members API for more information. - name: transactionId | type: string | description: [Transaction GUID](https://dev.wix.com/docs/rest/crm/loyalty-program/transactions/loyalty-transaction-object.md) for the transaction that created a coupon. - name: couponReference | type: CouponReference | description: Reference coupon information for the corresponding [coupon](https://dev.wix.com/docs/rest/business-management/marketing/coupons/coupons/coupon-object.md) that is created along with the loyalty coupon. - name: couponId | type: string | description: Coupon GUID. - name: code | type: string | description: Coupon code. Unique code entered by a customer to apply the coupon. - name: name | type: string | description: Name of coupon. - name: specification | type: Specification | description: The information to use when creating the coupon. - ONE-OF: - name: moneyOffAmount | type: number | description: Fixed price discount. - 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` on a site. - name: fixedPriceAmount | type: number | description: Specific sale price. Currently only supported for coupons with a `stores` `namespace`. - name: buyXGetY | type: BuyXGetY | description: Free products when making a purchase. `buyXGetY` is an object that specifies `x` and `y` in the following scenario: if a visitor purchases x number of products, they receive y number of products for free. C urrently only supported for coupons with a `stores` `namespace`. - 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. - ONE-OF: - name: scope | type: Scope | description: Scope of the coupon. When no scope is defined, the coupon applies to all items in all `namespaces` in the site. - name: name | type: string | description: Group within a `namespace` for which the coupon is applicable. If no group is specified, the coupon applies to all items in the namespace. `group` is required in some namespaces. See [Scope Values](https://dev.wix.com/api/rest/coupons/coupons/valid-scope-values) for a list of currently supported groups for each namespace. - name: entityId | type: string | description: GUID of the specific entity in the group for which the coupon is applicable. If no `entityId` is specified, the coupon applies to all entities in the group. In some cases when a group is specified, an `entityId` is required. See [Scope Values](https://dev.wix.com/api/rest/coupons/coupons/valid-scope-values) for a list of currently supported entities for each namespace and group. - name: namespace | type: string | description: Wix application for which the coupon is applicable. One of the following: + `"stores"` + `"bookings"` + `"events"` + `"pricingPlans"` - name: minimumSubtotal | type: number | description: The coupon is only applicable when the order subtotal is over this amount. - name: name | type: string | description: Name of coupon. - name: type | type: Type | description: - enum: UNKNOWN, MONEY_OFF_AMOUNT, PERCENT_OFF_RATE, FREE_SHIPPING, FIXED_PRICE_AMOUNT, BUY_X_GET_Y - name: limitedToOneItem | type: boolean | description: Whether the coupon is limited to 1 discount per order. If true and a customer pays for multiple items that the coupon applies to, only the lowest priced item is discounted. Coupons with a `bookings` `namespace` are always limited to 1 item. - name: appliesToSubscriptions | type: boolean | description: Whether the coupon also applies to subscriptions. - name: discountedCycleCount | type: integer | description: Specifies the amount of cycles to apply the discount to for a subscription item. Can only be set when `appliesToSubscriptions` is `TRUE` and `specification.scope.namespace` is `pricingPlans`. If `discountedCycleCount` is empty, the coupon applies to all available cycles. Min: `1` Max: `999` - name: deleted | type: boolean | description: Whether the referenced coupon was deleted. - name: status | type: Status | description: Loyalty coupon status. This status relates to the corresponding coupon that is created at the same time as the loyalty coupon and is included in `couponReference`. - enum: - UNKNOWN: Unknown status. - PENDING: The reference coupon was created but the loyalty points have not been redeemed yet. - ACTIVE: The reference coupon is active and available to the customer. - APPLIED: The reference coupon was applied and is no longer available for use. - FAILED: The reference coupon was created but something went wrong when redeeming points from the loyalty account. - ARCHIVED: The reference coupon was deleted. - name: rewardName | type: string | description: Name of reward that was redeemed to create this coupon. - name: revision | type: string | description: Revision number, which increments by 1 each time the loyalty coupon is updated. To prevent conflicting changes, the current `revision` must be passed when updating the loyalty coupon. - name: _createdDate | type: Date | description: Date and time the loyalty coupon was created. - name: _updatedDate | type: Date | description: Date and time the loyalty coupon was last updated. - name: refundable | type: boolean | description: Whether the loyalty coupon was created in a "refundable workflow" i.e. checkout-exchange, and therefore can be deleted in the background. Refundable coupons should not be visible to customers in the UI. - 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 { coupons } from '@wix/loyalty'; coupons.onCouponCreated((event) => { // handle your event here }); ``` ```javascript import { createClient, AppStrategy } from '@wix/sdk'; import { coupons } from '@wix/loyalty'; const wixClient = createClient({ auth: AppStrategy({ appId: 'MY-APP-ID', publicKey: 'YOUR_APP_PUBLIC_KEY', }), modules: { coupons, }, }); wixClient.coupons.onCouponCreated((event) => { // handle your event here }); ``` ---