> 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 # QueryLoyaltyCoupon # Package: rewards # Namespace: LoyaltyCoupons # Method link: https://dev.wix.com/docs/api-reference/crm/loyalty-program/rewards/coupons/query-loyalty-coupon.md ## Permission Scopes: Read Loyalty: SCOPE.DC-LOYALTY.READ-LOYALTY ## Introduction Retrieves a list of loyalty coupons, with the specified paging, filtering, and sorting. --- ## REST API ### Schema ``` Method: queryLoyaltyCoupon Description: Retrieves a list of loyalty coupons, with the specified paging, filtering, and sorting. URL: https://www.wixapis.com/v1/coupons/query Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: query Method parameters: param name: query | type: QueryV2 | required: true - ONE-OF: - required: true - name: paging | type: Paging | description: Paging options to limit and offset the number of items. - name: limit | type: integer | description: Number of items to load. - name: offset | type: integer | description: Number of items to skip in the current sort order. - name: cursorPaging | type: CursorPaging | description: Cursor token pointing to a page of results. Not used in the first request. Following requests use the cursor token and not `filter` or `sort`. - name: limit | type: integer | description: Maximum number of items to return in the results. - name: cursor | type: string | description: Pointer to the next or previous page in the list of results. Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request. - name: filter | type: object | description: Filter object. Learn more about [filtering](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#filters). - name: sort | type: array | description: Sort object. Learn more about [sorting](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#sorting). - name: fieldName | type: string | description: Name of the field to sort by. - name: order | type: SortOrder | description: Sort order. - enum: ASC, DESC - name: fields | type: array | description: Array of projected fields. A list of specific field names to return. If `fieldsets` are also specified, the union of `fieldsets` and `fields` is returned. - name: fieldsets | type: array | description: Array of named, predefined sets of projected fields. A array of predefined named sets of fields to be returned. Specifying multiple `fieldsets` will return the union of fields from all sets. If `fields` are also specified, the union of `fieldsets` and `fields` is returned. Return type: QueryLoyaltyCouponResponse - name: loyaltyCoupons | type: array | description: Retrieved loyalty coupons. - 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. - name: metadata | type: PagingMetadataV2 | description: Metadata. - name: count | type: integer | description: Number of items returned in the response. - name: offset | type: integer | description: Offset that was requested. - name: total | type: integer | description: Total number of items that match the query. Returned if offset paging is used and the `tooManyToCount` flag is not set. - name: tooManyToCount | type: boolean | description: Flag that indicates the server failed to calculate the `total` field. - name: cursors | type: Cursors | description: Cursors to navigate through the result pages using `next` and `prev`. Returned if cursor paging is used. - name: next | type: string | description: Cursor string pointing to the next page in the list of results. - name: prev | type: string | description: Cursor pointing to the previous page in the list of results. ``` ### Examples ### Query loyalty coupons ```curl curl -X POST \ 'https://www.wixapis.com/loyalty-coupons/v1/coupons/query' \ -H 'Authorization: ' -H 'Content-Type: application/json' \ --data-raw '{ "query": { "filter": {"memberId": {"$eq": "e64eee9f-ec4e-4c8a-b015-eb3be0b2761b"}} } }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.rewards.LoyaltyCoupons.queryLoyaltyCoupon(query) Description: Retrieves a list of loyalty coupons, with the specified paging, filtering, and sorting. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: query Method parameters: param name: query | type: CouponQuery | required: true - ONE-OF: - required: true - name: paging | type: Paging | description: Paging options to limit and offset the number of items. - name: limit | type: integer | description: Number of items to load. - name: offset | type: integer | description: Number of items to skip in the current sort order. - name: cursorPaging | type: CursorPaging | description: Cursor token pointing to a page of results. Not used in the first request. Following requests use the cursor token and not `filter` or `sort`. - name: limit | type: integer | description: Maximum number of items to return in the results. - name: cursor | type: string | description: Pointer to the next or previous page in the list of results. Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request. - name: filter | type: object | description: Filter object. Learn more about [filtering](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#filters). - name: sort | type: array | description: Sort object. Learn more about [sorting](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#sorting). - name: fieldName | type: string | description: Name of the field to sort by. - name: order | type: SortOrder | description: Sort order. - enum: ASC, DESC Return type: PROMISE - name: loyaltyCoupons | type: array | description: Retrieved loyalty coupons. - 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: PagingMetadataV2 | description: Metadata. - name: count | type: integer | description: Number of items returned in the response. - name: offset | type: integer | description: Offset that was requested. - name: total | type: integer | description: Total number of items that match the query. Returned if offset paging is used and the `tooManyToCount` flag is not set. - name: tooManyToCount | type: boolean | description: Flag that indicates the server failed to calculate the `total` field. - name: cursors | type: Cursors | description: Cursors to navigate through the result pages using `next` and `prev`. Returned if cursor paging is used. - name: next | type: string | description: Cursor string pointing to the next page in the list of results. - name: prev | type: string | description: Cursor pointing to the previous page in the list of results. ``` ### Examples ### Query loyalty coupons (with elevated permissions) ```javascript import { coupons } from "@wix/loyalty"; import { auth } from "@wix/essentials"; /* Sample query value: * * { * "query": { * "fieldsets": [], * "fields": [], * "sort": [], * "filter": { * "couponReference.name": { * "$eq": "10% off all events" * }, * "rewardName": { * "$startsWith": "10%" * } * } * } * } */ const elevatedQueryLoyaltyCoupons = auth.elevate(coupons.queryLoyaltyCoupons); async function queryLoyaltyCoupons(query) { try { const result = await elevatedQueryLoyaltyCoupons(query); return result; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * * { * "loyaltyCoupons": [ * { * "_id": "56826083-0c4a-4e62-88e3-c6978482bde9", * "accountId": "d0dc5ba3-4a10-4cfc-b304-c976d8ac7303", * "memberIdDeprecated": "7d368843-6f0c-4037-8d0e-b7e36a8a0c32", * "transactionId": "33490644-0f84-44e4-aa55-738b203fa4bd", * "couponReference": { * "couponId": "a6df2aeb-50fc-4b15-b18d-765be38a6513", * "code": "6QLGQ9RNNR9R", * "name": "10% off all events", * "specification": { * "name": null, * "type": "PERCENT_OFF_RATE", * "limitedToOneItem": false, * "appliesToSubscriptions": null, * "discountedCycleCount": null, * "percentOffRate": 10, * "scope": {"name": "ticket", "entityId": null, "namespace": "events"} * }, * "deleted": null * }, * "status": "ACTIVE", * "rewardName": "10% off all events", * "revision": "2", * "_createdDate": "2024-06-12T08:29:56.594Z", * "_updatedDate": "2024-06-12T08:29:56.851Z", * "memberId": "7d368843-6f0c-4037-8d0e-b7e36a8a0c32" * }, * { * "_id": "6fb2cdc0-863f-4b4b-b76d-a73608654aee", * "accountId": "d0dc5ba3-4a10-4cfc-b304-c976d8ac7303", * "memberIdDeprecated": "7d368843-6f0c-4037-8d0e-b7e36a8a0c32", * "transactionId": "0b24afeb-2964-4bb2-a5ab-b32e04128c20", * "couponReference": { * "couponId": "27d5d44d-eb61-4533-8f72-01177097e470", * "code": "6QLGLVTGVH8A", * "name": "10% off all events", * "specification": { * "name": null, * "type": "PERCENT_OFF_RATE", * "limitedToOneItem": false, * "appliesToSubscriptions": null, * "discountedCycleCount": null, * "percentOffRate": 10, * "scope": {"name": "ticket", "entityId": null, "namespace": "events"} * }, * "deleted": null * }, * "status": "ACTIVE", * "rewardName": "10% off all events", * "revision": "2", * "_createdDate": "2024-06-12T08:14:16.884Z", * "_updatedDate": "2024-06-12T08:14:17.403Z", * "memberId": "7d368843-6f0c-4037-8d0e-b7e36a8a0c32" * } * ] * } */ ``` ### Query loyalty coupons ```javascript import { coupons } from "@wix/loyalty"; /* Sample query value: * * { * "query": { * "fieldsets": [], * "fields": [], * "sort": [], * "filter": { * "couponReference.name": { * "$eq": "10% off all events" * }, * "rewardName": { * "$startsWith": "10%" * } * } * } * } */ async function queryLoyaltyCoupons(query) { try { const result = await coupons.queryLoyaltyCoupons(query); return result; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * * { * "loyaltyCoupons": [ * { * "_id": "56826083-0c4a-4e62-88e3-c6978482bde9", * "accountId": "d0dc5ba3-4a10-4cfc-b304-c976d8ac7303", * "memberIdDeprecated": "7d368843-6f0c-4037-8d0e-b7e36a8a0c32", * "transactionId": "33490644-0f84-44e4-aa55-738b203fa4bd", * "couponReference": { * "couponId": "a6df2aeb-50fc-4b15-b18d-765be38a6513", * "code": "6QLGQ9RNNR9R", * "name": "10% off all events", * "specification": { * "name": null, * "type": "PERCENT_OFF_RATE", * "limitedToOneItem": false, * "appliesToSubscriptions": null, * "discountedCycleCount": null, * "percentOffRate": 10, * "scope": {"name": "ticket", "entityId": null, "namespace": "events"} * }, * "deleted": null * }, * "status": "ACTIVE", * "rewardName": "10% off all events", * "revision": "2", * "_createdDate": "2024-06-12T08:29:56.594Z", * "_updatedDate": "2024-06-12T08:29:56.851Z", * "memberId": "7d368843-6f0c-4037-8d0e-b7e36a8a0c32" * }, * { * "_id": "6fb2cdc0-863f-4b4b-b76d-a73608654aee", * "accountId": "d0dc5ba3-4a10-4cfc-b304-c976d8ac7303", * "memberIdDeprecated": "7d368843-6f0c-4037-8d0e-b7e36a8a0c32", * "transactionId": "0b24afeb-2964-4bb2-a5ab-b32e04128c20", * "couponReference": { * "couponId": "27d5d44d-eb61-4533-8f72-01177097e470", * "code": "6QLGLVTGVH8A", * "name": "10% off all events", * "specification": { * "name": null, * "type": "PERCENT_OFF_RATE", * "limitedToOneItem": false, * "appliesToSubscriptions": null, * "discountedCycleCount": null, * "percentOffRate": 10, * "scope": {"name": "ticket", "entityId": null, "namespace": "events"} * }, * "deleted": null * }, * "status": "ACTIVE", * "rewardName": "10% off all events", * "revision": "2", * "_createdDate": "2024-06-12T08:14:16.884Z", * "_updatedDate": "2024-06-12T08:14:17.403Z", * "memberId": "7d368843-6f0c-4037-8d0e-b7e36a8a0c32" * } * ] * } */ ``` ### queryLoyaltyCoupons (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 { coupons } from '@wix/loyalty'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { coupons }, // Include the auth strategy and host as relevant }); async function queryLoyaltyCoupons(query) { const response = await myWixClient.coupons.queryLoyaltyCoupons(query); }; ``` ---