Functions
Functions and properties available on the discountNinja.api namespace.
The documentation below describes the API as of version 9.x of the script.
Public properties or functions that are not in the discountNinja.api
namespace should be considered obsolete and will be removed in the next major version release.
Using undocumented functions or objects will result in issues as custom code that relies on those functions or objects may break in the future when Discount Ninja's script is automatically updated.
Cache
Clear
Async | Yes |
Function |
|
Clears all session and local storage data used by the script. Also clears the content of the indexedDb used by the script. | |
Type | Public |
This function is intended for use in troubleshooting sessions. |
Syntax
Cart
Add
Async | Yes |
Function |
|
Adds a variant to the cart. Note: this is an asynchronous function; the result must be awaited. | |
Type | Public |
This function is intended for use in integration code by third parties. | |
Parameters |
|
| |
| |
|
Syntax
Content
Async | No |
Property |
|
Can be used to get access to an object that represents the content of the cart, including any discounts applied by Shopify's backend. | |
Type | Public |
This function is intended for use in integration code by third parties. | |
Return value |
|
Syntax
Prefill
Async | Yes |
Property |
|
Can be used to prefill a cart with specific variants. Typically used to create a link to a prefilled, discounted cart. Cf. https://support.discountninja.io/en/articles/5194395-how-to-build-a-prefilled-discounted-cart | |
Type | Public |
This function is intended for use in integration code by third parties. | |
Parameters |
|
This parameter is optional. If it is omitted, the app will look for a query parameter named | |
| |
This parameter is optional. If it is omitted, the app will look for a query paramer named |
Syntax: example 1
This script can be used on a cart template to automatically prefill the cart based on the query parameters as explained here: ttps://support.discountninja.io/en/articles/5194395-how-to-build-a-prefilled-discounted-cart
Syntax: example 2
Alternatively, create a variants array manually and then
Checkout
Is discounted
Async | Yes |
Function |
|
Can be used to check if any of the promotions apply to the cart and result in a product, order or shipping discount. | |
Type | Public |
This function is intended for use in integration code by third parties. | |
Return value |
The return value indicates if the app will instruct Shopify to apply discounts at checkout. Additionally, when this function returns |
Syntax
Add pipeline rule
Async | No |
Function |
|
Can be used to add custom business logic that is executed when the customer click the checkout button. | |
Discount Ninja needs to take over the checkout process when a user clicks the checkout button to ensure the checkout is correctly discounted. | |
As a result, the app overrides any logic you may have associated with clicking the checkout button. To execute this logic you can add it to the pipeline of rules that is executed by the app. | |
Each pipeline rule is a parameterless function that returns a boolean indicating if execution should continue ( | |
Type | Public |
This function is intended for use in integration code by third parties. | |
Return value |
|
Syntax
Discount code
Add
Async | Yes |
Function |
|
Adds a discount code or promotion code to the Discount Ninja promotion code field programmatically. | |
Type | Public |
This function is intended for use in integration code by third parties. | |
Parameters |
|
Syntax
Remove
Async | Yes |
Function |
|
Removes a discount code or promotion code from the Discount Ninja promotion code field programmatically. | |
Type | Public |
This function is intended for use in integration code by third parties. | |
Parameters |
|
Syntax
Discounted cart
Content
Property |
|
Can be used to get access to an object that represents the content of the cart, including any discounts applied by Shopify's backend. | |
Type | Internal |
This is an internal function or property. Use it only for debugging purposes. Do not rely on this function or property in your integration code. | |
Return value |
|
Syntax
Entitlements
Property |
|
Lists the entitlements that apply based on the available offers. The array contains one item for each available offer. It details the prerequisites that were found in the cart, the discount amount, the target products and the entitled line items that were found in the cart. | |
Type | Public |
This function is intended for use in integration code by third parties.. | |
Return value |
|
Syntax
Events
Subscribe
This function is not used to subscribe to events. Instead it is simply a helper function that prints sample code to the log console to explain how to subscribe to an event.
Async | No |
Function |
|
Provides instructions on how to subscribe to an event with a given name. Note: this function does not, itself, subscribe to the event. | |
See the list of available events. | |
Type | Public |
This function is intended for use in integration code by third parties. |
Syntax
Publish
Async | No |
Function |
|
Publishes an event to the PriceRuleEngine. | |
See the list of available events. | |
Type | Public |
This function is intended for use in integration code by third parties. |
Syntax
Help
Async | No |
Function |
|
Prints a link to this page on the console. | |
Type | Public |
This function is intended for use in integration code by third parties. |
Syntax
Line item
Get updated key
Async | No |
Function |
|
Returns the updated key associated with a cart line item. A key can be updated by Shopify's back-end when properties are added, a selling plan changes or a discount is added. Cf. https://support.discountninja.io/en/articles/9109023-fix-network-requests-to-cart-js | |
Type | Public |
This function is intended for use in integration code by third parties. | |
Parameters |
|
Return value |
|
Syntax
Offers
All
Async | No |
Function |
|
Lists all the active offers loaded by the app. | |
Type | Internal |
This function returns an internal object. Do not rely on the properties of this object in your integration code as they may be removed or renamed in future versions. | |
Return value |
|
Syntax
Get
Async | No |
Function |
|
Finds a specific offer in the list of all the active offers loaded by the app. | |
Type | Internal |
This function returns an internal object. Do not rely on the properties of this object in your integration code as they may be removed or renamed in future versions. | |
Parameters |
|
Return value |
|
Syntax
Promotions
All
Function |
|
Lists all the active promotions loaded by the app. | |
Type | Internal |
This function returns an internal object. Do not rely on the properties of this object in your integration code as they may be removed or renamed in future versions. | |
Return value |
|
Syntax
Get
Function |
|
Finds a specific promotion in the list of all the active promotions loaded by the app. | |
Type | Internal |
This function returns an internal object. Do not rely on the properties of this object in your integration code as they may be removed or renamed in future versions. | |
Parameters |
|
Return value |
|
Syntax
Trigger
Async | No |
Function |
|
Triggers a private promotion programmatically. | |
Use this as a programmatic alternative to using a discount link. To trigger a promotion based on a promotion code, use the Discount Code Add function instead. | |
Type | Public |
This function is intended for use in integration code by third parties. | |
Parameters |
|
Syntax
Strikethrough Pricing
Apply
Async | Yes |
Function |
|
Triggers a refresh of all strikethrough pricing programmatically. This is typically not required since the app automatically detects situations where the strikethrough pricing must be updated. | |
Type | Public |
This function is intended for use in integration code by third parties. |
Syntax
Last updated