Skip to main content
Version: 4.55.1

Digital Goods for Lenses

Digital Goods for Lenses are no longer supported, as Tokens are being discontinued. Please see this help article for more details.

Digital Goods are unique items within a Lens that Snapchatters can unlock with Snap Tokens. Examples include image enhancement features (e.g. photo editing tools), accessories (e.g. sunglasses), custom entertainment (e.g. exclusive sounds or music), and more! This guide will walk you through how to design, build, test, and publish Lenses that offer Digital Goods.

You must verify your eligibility and accept the Terms in My Lenses before proceeding further. Please visit this page to get started.

Types

Currently, Lens Studio supports two types of digital goods: durables and consumables. You can decide which one is best for your Lens experience. More types may become available in the future.

  1. Durables are digital goods that, once unlocked, persist within the Lens for the Snapchatter to revisit and reuse indefinitely. Examples: AR accessories or a color correction tool.
  1. Consumables are digital goods that can be set to expire after each use, or you can set up a balance that decreases after each use. Example: A Snapchatter can receive access to a daily horoscope once, or you can offer an opt-in to 30 days of access, which depletes by one each time they access their horoscope. When choosing to include a consumable digital good, please make sure to include details in the digital goods description in My Lenses so that Snapchatters understand how many times they are able to use it.

Digital Goods API & Lens Entitlement Service

Lenses featuring digital goods are powered by the Digital Goods API, which connects Lenses to the Lens Entitlement service. The Lens Entitlement service takes care of inventory management, including digital goods ownership and consumption.

The Digital Goods API is available in Lens Studio via a Remote Service Module. Developers can build, test, and publish Lenses with digital goods directly from Lens Studio. After publishing, monetization analytics are tracked in My Lenses.

The Remote Service Module is not yet generally available and will be provided to you. Refer to Building Your Lens.

Digital Goods Registration & Lifecycle

Digital goods are tracked via SKU. A SKU is a string that you choose to uniquely identify digital goods throughout the platform (in your Lens Studio project, in the Lens Entitlement service, and in My Lenses). Each SKU has the following metadata associated with it in the Lens Entitlement service:

  • Title
  • Description
  • Price
  • Item Type (durable or consumable)
  • Consumable Quantity (if consumable; amount added to balance on unlock)
  • Consumption Balance (if consumable; amount available for use)

Title, description, and price are shown in the Snapchat redemption UI, called the “purchase tray.” Digital goods metadata is also available for use in the Lens via the Digital Goods API. Refer to Building Your Lens for more information. You will populate metadata during the My Lenses submission process. See Publishing Your Lens.

Once a digital good is registered in My Lenses, the SKU and Item Type cannot be changed. SKUs cannot be deleted and the Lens content associated with the SKU must not change from what was offered. This ensures that after a Snapchatter unlocks a digital good, they continue to receive the value they expect.

You are permitted to add new SKUs to your Lens after publishing the initial version. To do so, you will need to republish your Lens.

What are Snap Tokens?

Snap Tokens can be purchased from inside the Snapchat app. In addition to Digital Goods in a Lens, Tokens can be used for Bitomji fashion drops and gifts to send to Snap Stars.

The Tokens Shop is accessed through the My Tokens section under My Profile on Snapchat. Here, Snapchatters can view their Snap Tokens balance and buy more Snap Tokens.

  • Snap Tokens cannot be used outside of the mobile Snapchat application.
  • Snap Tokens cannot be redeemed for real-world goods or services.
  • Snap Tokens cannot be shared or gifted to other Snapchatters.

Refer to the full Snap Tokens Terms of Sale and Use for more details.

Snap Token Price Points for Digital Goods

In determining the number of Snap Tokens required to unlock a digital good within your Lens, you must select from the Digital Good Token Price Points listed in the table below. For example, you cannot price your Digital Goods at 727 Snap Tokens, but you may price them at either 700 or 750 Snap Tokens. The value of 1 Snap Token is approximately $0.01 USD. Factors to consider for pricing digital goods include scarcity, uniqueness, and utility.

| Digital Good Token Price Points | | :-----------------------------: | :-: | :--: | :----: | | 1 | 200 | 700 | 1600 | | 5 | 225 | 750 | 1700 | | 10 | 250 | 800 | 1800 | | 15 | 275 | 850 | 1900 | | 20 | 300 | 900 | 2000 | | 25 | 350 | 950 | 2100 | | 50 | 400 | 1000 | 2200 | | 75 | 450 | 1100 | 2300 | | 100 | 500 | 1200 | 2400 | | 125 | 550 | 1300 | 2500 | | 150 | 600 | 1400 | 5000 | | 175 | 650 | 1500 | 10,000 |

Snap Token Packs

Snapchatters may purchase Snap Tokens in packages, the pricing of which may vary from country to country. In the United States, these Snap Token packages and the pricing for the same are as follows:

USD CostSnap Token Count
$0.9980 tokens
$1.99160 tokens
$2.99250 tokens
$3.99350 tokens
$4.99500 tokens
$7.99800 tokens
$9.991,100 tokens

To help Snapchatters learn and discover how to use Snap Tokens within Snapchat, Snap may distribute free or promotional Snap Tokens. Accordingly, free or promotional Snap Tokens may remain in circulation and they may be redeemed by Snapchatters to claim digital goods within your Lenses. Please refer to the Digital Goods for Lenses Terms to understand how redemption of free or promotional Snap Tokens for Digital Goods within your Lenses impacts your payment.

Developer Economics

Digital goods offer a new, exciting opportunity for you to monetize your Lenses.

If a user redeems Snap Tokens to unlock digital goods within your Lenses, then you may be eligible to receive a payment in an amount based on a share of net revenue. Any payments will be awarded in Crystals on a monthly basis on or around the beginning of each month, and you will be notified via a notification in Snapchat.

Designing Your Lens

With the help of developers like you, we are experimenting and learning. This section walks through Lens content tips, Freemium pricing, the purchase user flow, and general UI / UX guidance and resources.

Guidance may evolve over time as we receive more data.

Lens Content

The most successful Lenses featuring digital goods will offer experiences that Snapchatters easily understand and keep coming back to. They will feature digital goods that provide continuous value to Snapchatters. Consider the following guidance to help increase your conversion and retention rates:

  • Streamline your Lens: Put Snapchatters into the Lens experience right away. Minimize steps to find and unlock digital goods. Use clean, simple, uncluttered UI.
  • Update content regularly: Provide new content or upgrade existing digital goods regularly. Examples: Snapchatters can unlock an astrology Lens to get a daily horoscope, or unlock a makeup Lens to get daily or seasonal looks. This will encourage them to revisit the Lens.
  • Offer a service or tool: Similarly, offer an app-like experience that provides ongoing utility. Examples: a creative editing tool for photos/videos; daily sports information or augmenting a weather service (using our API libraries available in the Lens Studio Asset Library).
  • 5 items or less: Lenses with fewer digital goods tend to perform better. Currently, Snapchatters are used to swiping through Lenses quickly. They are less likely to stop and browse through many digital goods. Offer a maximum of 5 SKUs.
  • Remember previous state: Where applicable, save the state from the Snapchatter’s previous session using local or cloud persistent storage. E.g., for a wearable experience, store the last digital good worn by the Snapchatter and start the next Lens session on that item.

Local storage is simpler to implement but is cleared after 60 days if the Lens is not used. For data that is critical to the functionality of the digital good, use cloud storage (see Lens Cloud restrictions).

  • Pricing: Bias toward higher prices (>100). Even with a high conversion rate, a Lens’ revenue potential will be limited if priced too low. Prices for digital goods can be changed in My Lenses after publishing – try experimenting.

Storefront Model

Your storefront is the UI / UX that Snapchatters navigate to discover and unlock digital goods in your Lens. It should give Snapchatters a predictable way to:

  • Find and recognize digital goods in your Lens
  • Understand what a digital good is / does
  • Use Snap Tokens to unlock a digital good
  • Find and use previously unlocked digital goods

A carousel storefront is an example of a storefront model for digital goods.

Snapchatters can swipe through a carousel to easily view and select digital goods to unlock and interact with.

To aid in your Lens development, the Digital Goods Template provides a template that you can add your digital goods to, with no scripting required of you.

The project handles digital goods logic and demonstrates UI / UX best practices, detailed further below.

Freemium Development & Pricing

Lenses offering digital goods are required to use a Freemium development and pricing strategy, which offers part of the Lens experience for free and additional features / items available to unlock. Freemium experience limitations can include:

  • Feature / tool, e.g., one free color filter, then redeem Snap Tokens to unlock more editing tools
  • Item, e.g., one free hat, then redeem Snap Tokens to unlock other accessories
  • Interaction, e.g., one free Snap, then redeem Snap Tokens to take more Snaps
  • Time, e.g., ten second preview of face effect, then redeem Snap Tokens to unlock

The carousel example includes one free and four unlockable durables (i.e., sweatbands).

User Flow

Lenses with digital goods differ from traditional Lenses in that they require an end-to-end user flow involving multiple states.

The following chart outlines the basic user flow required for a Snapchatter to redeem Snap Tokens for digital goods in your Lens. States in black need to be designed by you, the Lens creator. States in yellow (i.e., the purchase tray) are handled by Snapchat.

Before building your Lens, map out your user flow.

Below is the carousel storefront user flow:

Digital Goods Icons

The following icons are provided to use in your Lens.

NameIcon
Locked
Unlocked
Token

Locked Durable Good UI

The UI element, button, or tap target that represents a durable digital good must be accompanied by a lock or Token icon, either overlapping, in the same container, or immediately next to the digital good UI.

In the carousel example project, carousel cards representing locked digital goods include a locked icon.

When a locked carousel item is in focus, an Unlock button is also present to trigger the purchase tray. Since the digital good in this example is wearable, the Snapchatter is blurred to protect the value of the locked digital good.

Purchase Tray & Digital Good Preview

The purchase tray is part of the native Snapchat app. It gets triggered by purchase interaction in your Lens, like the press of an Unlock button. You do not need to build the purchase tray. You are not permitted to auto-trigger the purchase tray without an explicit purchase interaction by the Snapchatter.

While the purchase tray is open, you can preview the digital good to Snapchatters to aid their decision to unlock. Options include:

  • Let the Snapchatter try on the digital good
  • Show a preview of what the digital good looks like
  • Use a custom asset to visualize the digital good

Unlocked Durable Good UI

Upon unlocking durable digital goods, the locked icon must either be replaced with an unlocked icon, or removed altogether.

In the carousel example project, the carousel card locked icon, button, and blur are disabled when an unlocked sweatband is in focus.

Consumable Good UI

Consumable digital goods must have an associated balance shown in the Lens UI. The balance must be updated as consumable digital goods are redeemed and used.

Capture Mode UI

Consider how your Lens will look when a Snapchatter takes a Snap. Enable and disable UI elements to make your Lens snappable. For example, disable your storefront UI in capture mode.

In the carousel example project, the carousel UI is disabled in snaps.

On locked items, the display is blurred in capture to protect the value of the wearable digital good in snaps.

On unlocked digital goods, the blur is disabled.

Server Error Handling

If a server error occurs while inventory is syncing on Lens start, an error message must be shown. Snapchatters must also be prevented from unlocking digital goods in this state, since their user inventory is unknown. Lens developers are responsible for handling server errors on Lens start.

In the carousel example project, the error message says “Sorry, something went wrong” and the carousel is disabled.

If an error occurs during Snap Token redemption, Snapchat will handle the error and show an error message in the purchase tray.

General UI / UX Best Practices & Resources

Button Best Practices

Your Lens design will likely include one or more buttons. Please follow these best practices for buttons on mobile devices:

  • Buttons should look pressable: Snapchatters should be able to easily tell that a button is a button. Use familiar shapes and layouts. Provide visual and / or audio feedback when a button press is detected.
  • Buttons should be easy to press: Buttons should be large enough to easily press with a finger on a mobile device.
  • Button text should be relevant, specific, and concise: Limit the text on a button to a single, descriptive verb that says what will happen when the button is pressed, e.g., Unlock.

Refer to the User Interface Helper and the UI Button custom component in the UI / UX Resources section below, which include button animations.

Localization

Your Lens will be available to Snapchatters in many countries around the world. It is highly recommended that you localize strings in your digital goods metadata to reach more customers. You will have the option to add localization to your digital goods metadata during the Lens submission process.

For Lens UI strings that are not included in digital goods metadata, the Lens Studio Localization feature can be used.

Safe Render Zone

In Lens Studio, put any 2D UI in the Safe Render Zone screen region. This ensures your Lens UI elements won’t overlap with Snapchat UI.

Resources

The following resources may be helpful to you as you design and build your UI / UX. Documentation is linked when available.

ResourceNotes
Digital Goods IconsLocked icon, unlocked icon, Snap Token icon.
User Interface Helper (UI System)A collection of UI widgets (button, slider, toggle, etc). Available in the Asset Library.
Carousel Example ProjectFace Lens with a carousel, button, blur on locked digital goods, purchase try preview, Live Camera and Capture Mode UI.
Layout ElementsCustom components that support auto-layouts, including horizontal and vertical layouts. Available in the Asset Library.
CanvasComponent that supports adding 2D layouts in 3D space.
UI ButtonCustom component with a configurable button. Available in the Asset Library.
UI Color PickerCustom component with a configurable color picker. Available in the Asset Library.
Gauss blurPost-effect available in Lens Studio via Objects panel + menu.

Building Your Lens

It’s time to build your Lens! A number of resources are provided in this section to help you build your Lens depending on your needs. Refer to the following table for suggested pathways:

ResourceUse if...
Digital Goods TemplateYou want to add your own durable digital goods content to the provided carousel storefront, no scripting required.
Digital Goods Blueprint TemplateYou want to see examples (e.g., code and setup) of how to implement your own durable and consumable goods.
Remote Assets HelpersYou want to store Lens content as remote assets to help manage Lens size and performance.

Add your digital goods in the Digital Goods Configurator in your project via the Digital Goods API remote service module before publishing your Lens. More info.

Lens Studio

  • The Lens Studio version for digital goods is 4.55 only. Download here.

Make sure a device is selected in the Lens Studio Preview panel. A device must be selected for the purchase tray simulation to work.

Troubleshooting Errors

If you encounter errors while building your Lens, refer to these troubleshooting notes:

Response Status Codes

CodeMeaningNotes
0Unknown Status CodeUnexpected, contact support.
1SuccessAPI call completed successfully!
2RedirectedUnexpected, contact support.
3Bad RequestCheck API call implementation for errors.
4Access DeniedCheck your Snapchat app version.
5Api Call Not FoundCheck API call implementation for errors.
6TimeoutCheck network connection.
7Request Too LargeUnexpected, contact support.
8Server Processing ErrorCheck the item is registered and has the expected type. For consumables, don’t allow an amount greater than the good’s balance to be spent. See note*. Otherwise, contact support.
9Request canceled by callerThe user opened the purchase tray and dismissed it or exited the Lens without unlocking the digital good.
10Internal: Framework ErrorClient or server error. If using Lens Studio, check the Preview panel has a device selected, e.g., iPhone X.
  • For example, if a consumable digital good has a balance of 3, check that a spend API call cannot be made that has a spend quantity of greater than 3. This check is included in the provided InventoryManager.js script.

Lens Cloud

Lens Cloud is not required for Lenses with digital goods but its services can be useful for powering digital goods experiences. For example, remote assets can be used to offer content-rich assets or to add new digital goods without increasing Lens size.

Please refer to the remote assets guide for helper scripts and setup instructions.

Lens Cloud Limits and Restrictions: If you use Lens Cloud to build your Lens experience, be aware of the following limits and restrictions to ensure your Lens works as intended:

Lens Technical Limits & Restrictions

Lenses with digital goods are subject to the same technical requirements (e.g., frame rate, Lens size) as traditional Lenses.

Lens Optimization

When your Lens is complete, it is worth taking time to cleanup and optimize your project. For example, delete any unused assets from the Resources panel to minimize Lens size. For more guidance on Lens Optimization, refer to this doc.

Testing Your Lens

Please thoroughly test your Lens for usability and reliability. Lenses with digital goods are held to a higher quality standard than traditional Lenses to assure Snapchatter customer satisfaction.

You can test your Lens directly from Lens Studio without needing to redeem Snap Tokens. A list of digital goods-specific test cases is provided below.

Testing from Lens Studio

As with traditional Lenses, you can test your Lens from Lens Studio using the Preview panel and push-to-device.

In the Preview panel, you can test your unlock flow with a simulated purchase tray. From the bottom of the Preview panel, you can change the simulated device and the render target displayed (Live camera vs. Capture mode).

A device must be selected. Do not select No Simulation, Horizontal, or Spectacles (2021). Make sure to enable Showing Snapchat UI.

After the purchase tray opens, you can tap Unlock to unlock the digital good or Cancel to close the purchase tray without unlocking the digital good.

To reset purchases in the Preview panel, click Clear Persistent Storage in the Preview panel top right menu.

The simulated purchase tray displays placeholders for item metadata, e.g., Item Name, Lens Name, Item Description, price XX. These placeholders will be populated with your digital good metadata in the published Lens. See Publishing Your Lens for instructions on how to add your digital good metadata during Lens submission.

You can also test your Lens on device by clicking Send to Snapchat in the top right of Lens Studio. You will be prompted to pair your device if not already paired.

Like in the Preview panel, the purchase tray will contain placeholder information when previewing your Lens on device. The title and description will contain test strings and the price will be set to 0. Purchases will persist when you navigate away from and back to the Lens in Snapchat.

Unlocking items in the pushed Lens will not redeem your personal Snap Tokens. Your account does not need to have Snap Tokens to test via push to device.

Inventory clears each time the Lens is pushed to your device, or when persistent storage is cleared in the Preview panel. I.e. Unlocked digital goods reset to locked.

Lens Studio Test Cases

Please complete the following test cases before publishing your Lens:

  • On Lens start, confirm Lens UI / UX appear as expected, e.g., default digital goods are accessible and locked digital goods appear locked.
  • Confirm that the Lens UI does not overlap with the Snapchat UI.
  • In the Preview panel, change the device simulation to multiple other devices. Confirm that the Lens UI / UX appear as expected with different display sizes..
  • For each item, trigger the purchase tray. Confirm that the purchase tray opens and Lens UI appears as expected while the purchase tray is open.
  • For each item, open the purchase tray and press Cancel. Confirm that the purchase tray closes and the item remains locked / consumable balance is unchanged.
  • For each digital good, open the purchase tray, press Unlock, and dismiss the purchase tray. Confirm that Lens UI / UX update as expected upon unlocking.
  • For each unlocked durable good, confirm that the item remains unlocked as you navigate to and from other parts of the Lens.
  • For each durable good, unlock the item and refresh the Preview panel. Confirm that the item remains unlocked.
  • For each consumable good, confirm that the item’s balance updates as expected once unlocked.
  • For each consumable good, confirm that the balance updates as expected upon use of the item.
  • For each consumable good, unlock and use the item and refresh the Preview panel. Confirm that the balance is as expected.
  • Take snaps throughout your user flow. Confirm items and scenarios where the Live Camera and Capture Mode UI differ appear as expected.
  • Take snaps of locked items. Confirm the Capture Mode UI appears as expected.

Push-to-Device Test Cases

As of Lens Studio 4.40, the Lens Studio logger can print logs from your paired device via Studio.log(“example log message”). This is helpful for testing!

  • For each durable item, unlock the item and then navigate away from and back to the Lens. Confirm that the item remains unlocked.
  • For each consumable item, unlock the item and then navigate away from and back to the Lens. Confirm that the balance is maintained.
  • For any Lens UI strings that are localized (excluding item information populated by the Digital Goods API), change your device language to another language that is expected to be localized. Confirm that strings appear as expected.
  • After unlocking a durable and / or consumable good, log out of Snapchat. Log back in and check that the item is still unlocked and / or the consumable balance is accurate.

Usability Test Cases

  • Ask someone who is unfamiliar with your Lens to use it. Ask them if there are any parts that are confusing or difficult to understand.

Publishing Your Lens

  • Add your digital goods to the Digital Goods Configurator in your project before publishing. Otherwise, you may not see the Lens Folder submission flow.
  • In order to publish the Lens to your user profile, the profile owner must meet our eligibility criteria and agree to the Digital Goods for Lenses terms.

To publish your Lens with digital goods from Lens Studio, follow these steps:

  1. In Lens Studio, press Project Info. Add / verify the Lens name, icon, and preview.

  2. Press Publish Lens. Log in to My Lenses if not already logged in.

    1. For a new Lens, Select a Lens Folder you would like to add your Lens to in My Lenses. If that folder doesn’t exist yet, press + Create new Lens Folder.
    1. To republish an existing Lens, press Update an Existing Lens. On subsequent screens, select the Lens Folder containing your Lens, and select the Lens to update.
  1. Populate your Lens information and then press Complete Meta Info.

  1. Add the metadata (title, description, price, consumable quantity if applicable) for each of your digital goods.

    Token Quantity cannot be 0.

    , add Localization for item title and description. Click + Add to add a language. Next, click the chevron to expand the input fields. Enter your translated strings for title and description. Double check that the item information you have entered is correct.

  2. Once all items are populated, press Finish.

  1. Press Submit Lens.

Once submitted, your Lens and digital goods will go through automated testing and moderation. In addition to Snap’s Submission Guidelines, Lenses with digital goods are subject to the Guidelines and Restrictions outlined in About In-Lens Digital Goods. Your Lens will be published upon successful review and receipt of your signed Snap In-Lens Digital Goods Terms.

The typical review turnaround time for Lenses with digital goods is 24 hours, however, some reviews may take longer than traditional Lenses.

If your Lens is rejected, you will receive the reason for rejection by email and in My Lenses. Please address the issues and republish your Lens.

Lenses with digital goods cannot be deleted from My Lenses unless removal is required to comply with the Digital Goods for Lenses Terms.

Viewing Your Analytics

Digital goods analytics are available in My Lenses. To view your data, open Lens Insights and click on the Monetization tab. Select a Lens Folder from the top right drop-down menu, and a Lens from the top middle dropdown to view Lens-specific data.

If you’d like to return to viewing All Lenses, select My Community Lenses from the Lens Folder menu at the top right of the page.

My Lenses includes the following Monetization analytics for your Lens(es):

MetricDescription
Number of Digital Goods Card OpensThe number of times Snapchatters have opened the purchase tray.
Number of CancelsThe number of times Snapchatters have opened and closed the purchase tray without unlocking the item.
Number of Digital Goods UnlockedThe total quantity of digital goods that have been unlocked.
Number of Digital Goods Unlocked per UserThe number of items unlocked per unique Snapchatter.
Number of Users UnlockedThe number of unique Snapchatters that have unlocked items.
Total Snap Tokens UsedThe total quantity of Snap Tokens Snapchatters have used to unlock the digital goods in your Lenses.

Digital Goods API

This Section documents the Digital Goods API and its wrapper scripts. It is intended for technically proficient developers who want to: a) start their Lens Studio project from scratch, or b) add digital goods to an existing project.

As the developer, you are responsible for ensuring the quality of your custom implementation. Please thoroughly test your Lens for reliability and usability.

Getting Started with Digital Goods API

Follow these steps to add the Digital Goods API to your Lens Studio project:

  1. Download the DigitalGoodsAPI.lso.
  2. Import the DigitalGoodsAPI.lso into your project via File > Import, or by dragging it into the Resources panel. Put the Inventory Manager at the top of the hierarchy.

The DigitalGoodsAPI.lso contains the following resources that are meant to be used in any Lens featuring digital goods:

NameDescription
Digital Goods API [EDIT_ME]Remote service module
DigitalGoodsAPIModuleAPI wrapper script
EventModuleScript that enables JavaScript based events
InventoryManagerScript that syncs and stores digital goods inventory; defines syncs events and global functions for making API calls and getting digital good metadata

Remote Service Module

The Digital Goods API [EDIT_ME] resource is a remote service module that connects your Lens to the Lens Entitlement service. It is an input to the InventoryManager.js script and is required to make Digital Goods API calls.

The Digital Goods API remote service module provides the Digital Goods Configurator, which is where you register digital goods to your Lens. To access the Digital Goods Configurator, click on Digital Goods API [EDIT_ME] in the Resources panel. The Digital Goods Configurator will appear in the Inspector panel.

To add an item to the Digital Goods Configurator:

  1. Click + Add Config.
  2. Enter a unique string in the SKU field.
  3. Select the Type from the dropdown (Durable or Consumable).
  4. For consumable items, enter the Quantity that is added to the digital good’s balance on unlock.

You will add additional item metadata (i.e., title, description, price) for each item during the submission process.

SKU and Type cannot be changed once your Lens is published. After publishing your Lens, you are permitted to add new digital goods to your Lens. For the new SKUs to take effect, you must republish your Lens.

Scripts

InventoryManager.js

The InventoryManager.js script defines global functions and sync events that can be called from other scripts to implement your digital goods UI. It requires the Digital Goods API Module script and takes the Digital Goods API remote service module as an input.

Do not modify this script.

Global Functions

global.inventory.getBalance(String sku) : Number

Returns the consumption_balance of a consumable good. If sku is invalid, returns -1.

global.inventory.getDescription(String sku) : String

Returns the description registered to a digital good in My Lenses. When testing in the Lens Studio Preview panel, a placeholder value of “sku description” is returned. When testing via Lens Studio push to device, a placeholder value of “test item sku” is returned. If sku is invalid, returns “Description not found, check sku.”

global.inventory.getPrice(String sku) : Number

Returns the price registered to a digital good in My Lenses. When testing in the Lens Studio Preview panel, a placeholder value of 1 is returned. When testing via Lens Studio push to device, a placeholder value of 0 is returned. If sku is invalid, returns -1.

global.inventory.getQuantity(String sku) : Number

Returns the quantity added to a consumable good’s balance on purchase, as entered in the Digital Goods Configurator. If sku is invalid, returns -1.

global.inventory.getTitle(String sku) : String

Returns the title registered to a digital good in My Lenses. When testing in the Lens Studio Preview panel, a placeholder value of “sku title” is returned. When testing via Lens Studio push to device, a placeholder value of “test item sku” is returned. If sku is invalid, returns “Title not found, check sku.”

global.inventory.getUnlocked(String sku) : Boolean

Returns whether a digital good is locked (false) or unlocked (true). If sku is invalid, returns false.

global.inventory.purchaseItem(String sku, function successCallback, function failureCallback) : void

Triggers the purchase tray to open for a digital good. If the user unlocks the digital good, successCallback is called. If the user dismisses the purchase without unlocking, failureCallback is called (optional).

global.inventory.spendConsumable(String sku, Number spendQuantity, function successCallback, function failureCallback) : void

Deducts spendQuantity amount from a consumable good’s consumption_balance. If the API call is successful, successCallback is called. If the API returns an error, failureCallback is called (optional).

global.inventory.syncSuccess.add(function successCallback) : void

Adds a callback function to be executed when the global event, syncSuccess, is triggered when inventory syncs successfully.

global.inventory.syncFailure.add(function failureCallback) : void

Adds a callback function to be executed when the global event, syncFailure, is triggered when inventory fails to sync.

DigitalGoodsAPIModule.js

The DigitalGoodsAPIModule.js script is a wrapper for the Digital Goods API endpoints. It defines the API calls and handles responses. It is required by the InventoryManager. Learn more about Script Modules here.

Do not modify this script.

EventModule.js

The EventModule.js script provides helper classes for using JavaScript-based events. It is used by the InventoryManager to define and trigger events to notify other scripts that inventory has successfully (syncSuccess) or unsuccessfully (syncFailure) synced. Other scripts can define and bind callbacks to these events (see InventoryManager section).

Do not modify this script.

Digital Goods API

Digital Goods API endpoints are provided here for reference. However, it is highly recommended that you use the provided scripts bundled in DigitalGoodAPI.lso in your project rather than implementing API calls from scratch.

Endpoints

This section documents the API endpoints for the Digital Goods API.

get_store_inventory


Returns an array of digital goods metadata registered to the Lens.

Parameters: None

Response:

NameTypeDescription
item_listStoreItem[]Array of StoreItem objects registered in the Digital Goods Configurator.

get_user_inventory


Returns an array of digital goods owned by the user.

Parameters: None

Response:

NameTypeDescription
item_listUserItem[]Array of UserItem objects that have been unlocked by the user

purchase_item_entitlement


Triggers the Snapchat purchase tray to open.

Parameters:

NameTypeDescription
item_skuStringA unique identifier for a digital good

Response: None

spend_consumable_items


Reduces the consumption_balance of a consumable good.

Parameters:

NameTypeDescription
item_skuStringA unique identifier for a digital good
spend_quantityNumberAmount by which the consumable item’s consumption_balance is reduced

Response: None

Types

This section documents the data types returned by the Digital Goods API.

StoreItem (JSON)
NameTypeDescription
consumable_quantityNumberThe amount of a consumable good added to it’s consumption_balance on unlock
descriptionStringA user-facing explanation of what a user gets by unlocking a digital good
item_skuStringA unique identifier for a digital good
item_typeString“consumable” or “durable”
priceNumberThe cost of a digital good in Snap Tokens
titleStringA user-facing name for a digital good
UserItem (JSON)
NameTypeDescription
consumption_balanceNumberThe amount of a consumable good that is available for use
item_skuStringA unique identifier for a digital good
Was this page helpful?
Yes
No