> 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 # GetEligibleTriggers # Package: discounts # Namespace: CustomTriggersProvider # Method link: https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/extensions/discounts/custom-discount-triggers-integration-service-plugin/get-eligible-triggers.md ## Introduction Retrieves eligible custom discount triggers based on the provided items. This method is automatically called by Wix eCommerce to retrieve the custom discount triggers provided by your extension. This happens when actions are performed on the cart and checkout entities/pages. For example, when an item is added to the cart. --- ## REST API ### Schema ``` Method: getEligibleTriggers Description: Retrieves eligible custom discount triggers based on the provided items. This method is automatically called by Wix eCommerce to retrieve the custom discount triggers provided by your extension. This happens when actions are performed on the cart and checkout entities/pages. For example, when an item is added to the cart. URL: null Method: POST Method parameters: param name: lineItems | type: array | description: List of line items in the cart/checkout. - name: id | type: string | description: Line item GUID. - name: quantity | type: integer | description: Item quantity in this line item. - name: catalogReference | type: CatalogReference | description: Catalog and item reference. Holds GUIDs for the item and the catalog it came from, as well as further optional info. This field may be empty in the case of a custom line item. - name: catalogItemId | type: string | description: GUID of the item within the catalog it belongs to. - name: appId | type: string | description: GUID of the app providing the catalog. You can get your app's GUID from its page in the [app dashboard](https://dev.wix.com/dc3/my-apps/). For items from Wix catalogs, the following values always apply: + Wix Stores: `"215238eb-22a5-4c36-9e7b-e7c08025e04e"` + Wix Bookings: `"13d21c63-b5ec-5912-8397-c3a5ddb27a97"` + Wix Restaurants: `"9a5d83fd-8570-482e-81ab-cfa88942ee60"` - name: options | type: object | description: Additional item details in `key:value` pairs. Use this optional field for more specificity with item selection. The values of the `options` field differ depending on which catalog is providing the items. For Wix Stores products, learn more about integrating with [Catalog V3](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/e-commerce-integration.md) or [Catalog V1](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v1/catalog/e-commerce-integration.md), depending on [the version the site uses](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-versioning/introduction.md). - name: price | type: string | description: Price of a single item. param name: purchaseFlowId | type: purchaseFlowId | description: Persistent GUID that correlates between the various eCommerce elements: cart, checkout, and order. param name: shippingInfo | type: ShippingInfo - name: address | type: Address | description: Address (if applicable). - name: country | type: string | description: Two-letter country code in [ISO-3166 alpha-2](https://www.iso.org/obp/ui/#search/code/) format. - name: subdivision | type: string | description: Code for a subdivision (such as state, prefecture, or province) in [ISO 3166-2](https://www.iso.org/standard/72483.html) format. - name: city | type: string | description: City name. - name: preferredShippingOptionCode | type: string | description: Preferred shipping option code. For example, "usps_std_overnight". param name: triggers | type: array | description: List of triggers to be checked for discount eligibility. - name: customTrigger | type: CustomTrigger | description: Custom trigger info. - name: id | type: string | description: Custom trigger GUID. - name: identifier | type: string | description: Unique trigger identifier. The same value must be returned in `eligibleTriggers[i].identifier`. Return type: GetEligibleTriggersResponse - name: eligibleTriggers | type: array | description: List of eligible triggers. These are used by the Discount Rules API and Wix eCommerce to apply the relevant discount. - name: customTriggerId | type: string | description: Custom trigger GUID. Must be passed with relevant `identifier`. - name: identifier | type: string | description: Unique trigger identifier. The value must be the same as its equivalent in `triggers[i].identifier` in the request payload. ``` ### Examples ### Get eligible custom triggers - decoded JWT The data payload will include the following object as an encoded JWT. For the purposes of this example, we show the request and response objects decoded. ```curl curl -X POST https://provider.example.com/v1/getEligibleTriggers \ -H 'user-agent: Wix' \ -H 'accept-encoding: gzip, deflate' \ -H 'content-type: text/plain; charset=utf-8' --data-binary '{ "triggers": [ { "customTrigger": { "id": "my-happy-hour-trigger" }, "identifier": "123" }, { "customTrigger": { "id": "my-digital-sale-trigger" }, "identifier": "234" } ], "lineItems": [ { "catalogReference": { "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", "catalogItemId": "b8b60eb2-f0c0-2519-c884-4e45ba25f0f7" }, "id": "00000000-0000-0000-0000-000000000001", "price": "250.00", "quantity": { "value": 1 } }, { "catalogReference": { "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", "catalogItemId": "c11f4db2-50cd-f4ea-d278-18c0914215d9" }, "id": "00000000-0000-0000-0000-000000000002", "price": "215.00", "quantity": { "value": 1 } } ] } ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.discounts.CustomTriggersProvider.getEligibleTriggers(request, metadata) Description: Retrieves eligible custom discount triggers based on the provided items. This method is automatically called by Wix eCommerce to retrieve the custom discount triggers provided by your extension. This happens when actions are performed on the cart and checkout entities/pages. For example, when an item is added to the cart. Method parameters: param name: metadata | type: Context | description: this message is not directly used by any service, it exists to describe the expected parameters that SHOULD be provided to invoked Velo methods as part of open-platform. e.g. SPIs, event-handlers, etc.. NOTE: this context object MUST be provided as the last argument in each Velo method signature. Example: ```typescript export function wixStores_onOrderCanceled({ event, metadata }: OrderCanceledEvent) { ... } ``` - name: requestId | type: string | description: A unique identifier of the request. You may print this GUID to your logs to help with future debugging and easier correlation with Wix's logs. - name: currency | type: string | description: [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) 3-letter currency code. - name: identity | type: IdentificationData | description: An object that describes the identity that triggered this request. - 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: languages | type: array | description: A string representing a language and region in the format of `"xx-XX"`. First 2 letters represent the language code according to ISO 639-1. This is followed by a dash "-", and then a by 2 capital letters representing the region according to ISO 3166-2. For example, `"en-US"`. - name: instanceId | type: string | description: The service provider app's instance GUID. param name: request | type: GetEligibleTriggersRequest - name: lineItems | type: array | description: List of line items in the cart/checkout. - name: _id | type: string | description: Line item GUID. - name: quantity | type: integer | description: Item quantity in this line item. - name: catalogReference | type: CatalogReference | description: Catalog and item reference. Holds GUIDs for the item and the catalog it came from, as well as further optional info. This field may be empty in the case of a custom line item. - name: catalogItemId | type: string | description: GUID of the item within the catalog it belongs to. - name: appId | type: string | description: GUID of the app providing the catalog. You can get your app's GUID from its page in the [app dashboard](https://dev.wix.com/dc3/my-apps/). For items from Wix catalogs, the following values always apply: + Wix Stores: `"215238eb-22a5-4c36-9e7b-e7c08025e04e"` + Wix Bookings: `"13d21c63-b5ec-5912-8397-c3a5ddb27a97"` + Wix Restaurants: `"9a5d83fd-8570-482e-81ab-cfa88942ee60"` - name: options | type: object | description: Additional item details in `key:value` pairs. Use this optional field for more specificity with item selection. The values of the `options` field differ depending on which catalog is providing the items. For Wix Stores products, learn more about integrating with [Catalog V3](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/e-commerce-integration.md) or [Catalog V1](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v1/catalog/e-commerce-integration.md), depending on [the version the site uses](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-versioning/introduction.md). - name: price | type: string | description: Price of a single item. - name: triggers | type: array | description: List of triggers to be checked for discount eligibility. - name: customTrigger | type: CustomTrigger | description: Custom trigger info. - name: _id | type: string | description: Custom trigger GUID. - name: identifier | type: string | description: Unique trigger identifier. The same value must be returned in `eligibleTriggers[i].identifier`. - name: purchaseFlowId | type: string | description: Persistent GUID that correlates between the various eCommerce elements: cart, checkout, and order. - name: shippingInfo | type: ShippingInfo | description: Shipping information. - name: address | type: Address | description: Address (if applicable). - name: country | type: string | description: Two-letter country code in [ISO-3166 alpha-2](https://www.iso.org/obp/ui/#search/code/) format. - name: subdivision | type: string | description: Code for a subdivision (such as state, prefecture, or province) in [ISO 3166-2](https://www.iso.org/standard/72483.html) format. - name: city | type: string | description: City name. - name: preferredShippingOptionCode | type: string | description: Preferred shipping option code. For example, "usps_std_overnight". Return type: PROMISE - name: eligibleTriggers | type: array | description: List of eligible triggers. These are used by the Discount Rules API and Wix eCommerce to apply the relevant discount. - name: customTriggerId | type: string | description: Custom trigger GUID. Must be passed with relevant `identifier`. - name: identifier | type: string | description: Unique trigger identifier. The value must be the same as its equivalent in `triggers[i].identifier` in the request payload. ``` ### Examples ### Example of an `eligibleTriggers` return value ```javascript import { customTriggers } from '@wix/ecom/service-plugins'; customTriggers.provideHandlers({ getEligibleTriggers: async ( payload ) => { const {request, metadata} = payload; // Use the `request` and `metadata` received from Wix and // apply custom logic. return { // Return your response exactly as documented to integrate with Wix. // Return value example: eligibleTriggers: [ { customTriggerId: "my-happy-hour-trigger", identifier: "123" }, { customTriggerId: "my-digital-sale-trigger", identifier: "234" } ] } } }); ``` ### getEligibleTriggers (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 { customTriggers } from '@wix/ecom/service-plugins'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { customTriggers }, // Include the auth strategy and host as relevant }); async function getEligibleTriggers(request,metadata) { const response = await myWixClient.customTriggers.getEligibleTriggers(request,metadata); }; ``` ---