LootLocker
The BasicsGame SystemsContent ManagementPlayer Management
LootLocker
  • 📌The Basics
    • Getting Started
    • What is LootLocker?
    • Core Concepts
      • Players
      • Assets
      • Character Classes
      • API Types
      • Web Console
      • Stage & Live Environments
      • Glossary
    • Unity Quick Start
      • Install the SDK
      • Configure the SDK
      • Authenticate Your First Player
      • Update the SDK
    • Unreal Quick Start
      • Install & Configure the SDK
        • Older versions
      • Authenticate Your First Player
    • Godot Quick Start
      • Install the SDK
      • Configure the SDK
      • Authenticate Your First Player
      • Update the SDK
    • SDKs
    • Samples
      • Authentication Samples
      • Leaderboard Samples
      • Progression Samples
      • Player Samples
    • Launching Your Game
    • Support
      • Error Codes
      • Unreal Marketplace Plugin Support
  • 🎭Players
    • Overview
    • Authentication
      • How To
        • Guest Login
        • Steam
        • Apple
        • Apple Game Center
        • Google
        • Epic Games
        • PlayStation
        • Meta / Oculus
        • Xbox
        • Nintendo Switch
    • Files
      • How To
        • Manage Files in Web Console
        • Work with Files In-Game
    • Inventory
      • How To
        • Work with Player Inventory
    • Messages
      • How To
        • Configure Messages in Web Console
    • Names
      • How To
        • Work with Player Names
    • Player Manager
      • How To
        • Manage Players through Web Console
        • Manage Players In-Game
        • Use Player Operations
    • Unified Player Accounts
      • How To
        • Configure UPA in Web Console
        • Use Remote Login In-Game
        • Connect Identiy Provider to Player
        • External Provider Linking
        • Transition from Guest Login to Other Provider
        • Disconnect Identity Provider from Player
    • White Label Login
      • How To
        • Configure White Label Login
        • Create a New White Label User
        • Request User Verification
        • Handle Returning Users
        • Start a White Label Session
  • 🪙Commerce
    • Overview
    • Catalogs
      • How To
        • Configure Catalogs in LootLocker Console
        • List all Catalogs
        • Use Catalogs In-Game
        • Setup In-Game Store
    • Currencies
      • How To
        • Configure a Currency in Web Console
        • Use Currencies In-Game
    • DLC Management
      • How To
        • Configure DLC in Web Console
        • Use DLC In-Game
    • Entitlements
      • How To
        • Work with Entitlements In-Game
    • Real Money Purchases
      • How To
        • Configure In-App Purchase in Web Console
        • Make Purchases through Google Play Store
        • Make Purchases through Apple Store
        • Make Purchases through Steam Store
    • Virtual Purchases
    • Wallets
      • How To
        • Manage a Wallet in Web Console
        • Use Wallets In-Game
  • ⚔️Content
    • Overview
    • Assets
      • How To
        • Create & Configure an Asset
        • Organize & Search for Assets
        • Retrieve Assets In-Game
        • Set up Asset Storage Template
        • Check Grant Notifications
        • Set up a Game Config Asset
        • Create a Loot Box
        • Work with Loot Boxes In-Game
        • Create a Drop Table
        • Work with Drop Tables In-Game
        • Create a Rental Asset
        • Work with Rental Assets In-Game
    • User Generated Content (UGC)
      • How To
        • Create UGC In-Game
    • Twitch Drops
  • 🕹️Game Systems
    • Overview
    • Classes & Heroes
      • How To
        • Base Classes
        • Hero Classes
        • Implement Classes In-Game
        • Implement Heroes In-Game
    • Leaderboards
      • How To
        • Configure Leaderboard in Web Console
        • Use Player Leaderboards
        • Use Generic Leaderboards
        • Use Metadata to Store Additional Information
        • Use Scheduled Reset with Rewards
        • Use Leaderboards for Time Based Rankings
      • Leaderboard FAQ
      • GameMaker References
    • Feedback
      • How To
        • Manage Feedback Categories
        • Create Player Feedback
        • Create UGC Feedback
        • Create Game Feedback
        • View and Manage Feedback
    • Progressions
      • How To
        • Create a Progression
        • Game Progressions
        • Player Progressions
        • Class Progressions
        • Asset Instance Progressions
    • Triggers
      • How To
        • Setup a trigger in the Web Console
        • Invoke trigger from game
  • ⛓️Shared Systems
    • Overview
    • Metadata
      • How To
        • Add Metadata in Console
        • Fetch a Single Metadata In-Game
        • Fetch Metadata In-Game by Tags
        • Fetch Metadata In-Game from Multiple Sources
    • Notifications
      • How To
        • List Notifications and Mark as Read In-Game
  • 🗝️Admin
    • Settings
    • User Settings
    • Organization Settings
    • CORS Allowlist
  • ⭕️ Legacy
    • Deprecations
      • Unity SDK Deprecation Log
        • Version 2.1.5 - Migration to Open UPM
        • Version 2.0.0
      • Unreal SDK Deprecation Log
        • Version 4.0.0
        • Version 3.0.0
    • Legacy Storage
    • Legacy Triggers
      • Activate a trigger
      • Create a trigger
    • Legacy Progressions
      • Create a Progression System
      • Use a Progression System In-Game
Powered by GitBook
On this page
  • Prerequisites
  • Conclusion
  1. Shared Systems
  2. Notifications
  3. How To

List Notifications and Mark as Read In-Game

PreviousHow ToNextSettings

Last updated 5 months ago

In this How-to, we’ll get all unread notifications for the logged in player, find a specific notification by a key and mark it as read.

Prerequisites

  • A LootLocker account and a created game

  • A or a setup in the web console

  • A previously or a

To get the matched notification to a previous action (an invoked trigger, a purchase call), you need one or more of the following:

  • A purchase using virtual currency: use the catalog_listing_id

  • An In App Purchase using Apple App Store: use the transaction_id

  • An In App Purchase using Google Pla Store: use the product_id

  • An In App Purchase using Steam Store: use the entitlement_id

  • A trigger: use the trigger_key

// We're only interested in unread notifications for this how to.
// If you want to see information about notifications you've previously marked as read then set this to true
bool showRead = false;

// The key that we saved from invoking a trigger, or calling a purchase to get the correct notification
string notificationKey = "saved_trigger_key_or_catalog_item_id_from_a_previous_response";

// You can optionally return only a specific priority
LootLocker.LootLockerEnums.LootLockerNotificationPriority? priority = null;

// You can optionally return only a specific type of notification. 
// Triggers and purchased items are of the type LootLocker.LootLockerStaticStrings.LootLockerNotificationTypes.PullRewardAcquired
string ofType = "";

// The source of the notification: a type of purchase or trigger.
// Use the static strings provided in LootLocker.LootLockerStaticStrings.LootLockerNotificationSources 
// to specify what type of notification you are requesting.
// For purchases, use: 
// LootLocker.LootLockerStaticStrings.LootLockerNotificationSources.Purchasing.(the source of purchase: LootLocker, AppleAppStore, GooglePlayStore, SteamStore)
// For triggers, use: 
// LootLocker.LootLockerStaticStrings.LootLockerNotificationSources.Triggers
string notificationSource = LootLocker.LootLockerStaticStrings.LootLockerNotificationSources;

// The Page and Count parameters are used for pagination.
// Count means count per page, and Page is what page to access.
// For example: A count of 100, and page 2 would list all notifications (if any) from 101-201
int count = 10;
int page = 1;
LootLockerSDKManager.ListNotifications(showRead, priority, LootLockerNotificationTypes.PullRewardAcquired, notificationSource, count, page, (response) =>
{
    if (!response.success)
    {
        Debug.Log("Error, could not list notifications:" + response.errorData.message);
        // Add your own code here to handle the error
        return;
    }

    // A notifications request returns success even if no notifications were found,
    // handle that by checking if the notifications returned are null
    if (response.Notifications == null)
    {
        Debug.LogWarning("Error: no notifications found");
        // Add your own code to handle what should happen
        return;
    }

    // Get the desired notification
    LootLockerNotification[] matchingNotifications;
    bool notificationWasFound = response.TryGetNotificationsByIdentifyingValue(notificationKey, out matchingNotifications);
    
    if ( !notificationWasFound || matchingNotifications?.Length == 0 ) 
    {
        Debug.LogWarning("Error: Notification not found.");
        // Add your own code here to handle the error
        return;
    }

    // In this example we know that the trigger has only been invoked once so we can safely access the first element of the array
    LootLockerNotification desiredNotification = matchingNotifications[0];

    if (desiredNotification == null)
    {
        Debug.LogWarning("Error: Notification not found.");
        // Add your own code here to handle the error
        return;
    }

    // The enum value in the notification.Content.Body.Kind field shows what type of "thing" was rewarded, use that to know which field in the body contains the data about the reward.
    switch (desiredNotification.Content.Body.Kind)
    {
        case LootLocker.LootLockerEnums.LootLockerNotificationContentKind.group:
            // The reward is a reward group which contains a list of "associations". Ie, a list of assets, currencies, or other similar things rewarded as one in this single reward.
            // Handle this in line with your game logic 
            Debug.Log($"Trigger with key '{notificationKey}' gave reward of type group. The group has name '{desiredNotification.Content.Body.Group.Name}', description '{desiredNotification.Content.Body.Group.Description}'. and {desiredNotification.Content.Body.Group.Associations.Length} associations.");
            break;
        case LootLocker.LootLockerEnums.LootLockerNotificationContentKind.currency:
            // The reward is a currency. Handle this in line with your game logic 
            Debug.Log($"Trigger with key '{notificationKey}' gave reward of type currency: {desiredNotification.Content.Body.Currency.Details.Amount} {desiredNotification.Content.Body.Currency.Details.Code}");
            break;
        case LootLocker.LootLockerEnums.LootLockerNotificationContentKind.asset:
            // The reward is an asset. Handle this in line with your game logic 
            Debug.Log($"Trigger with key '{notificationKey}' gave reward of type asset with name '{desiredNotification.Content.Body.Asset.Details.Name}'");
            break;
        case LootLocker.LootLockerEnums.LootLockerNotificationContentKind.progression_reset:
            // The reward is a progression reset. Handle this in line with your game logic 
            Debug.Log($"Trigger with key '{notificationKey}' gave reward of type progression reset which resets the progression named '{desiredNotification.Content.Body.Progression_reset.Details.Name}'");
            break;
        case LootLocker.LootLockerEnums.LootLockerNotificationContentKind.progression_points:
            // The reward is progression points. Handle this in line with your game logic 
            Debug.Log($"Trigger with key '{notificationKey}' gave reward of type progression points which gives the player {desiredNotification.Content.Body.Progression_points.Details.Amount} points in the progression named '{desiredNotification.Content.Body.Progression_points.Details.Name}'");
            break;
        default:
            Debug.LogWarning($"Unhandled case {desiredNotification.Content.Body.Kind.ToString()}");
            break;
    }
    
    // After you've handled the notification in your game logic, remember to mark it as read.
    // This way it will not be returned on the next request unless you specifically request notifications marked as read.
    desiredNotification.MarkThisNotificationAsRead((response) =>
    {
        if (response.success)
        {
            Debug.Log("Marked notification as read");
        }
        else
        {
            Debug.LogWarning("Error marking notification as read: " + response.errorData.message);
            // Add your own code here to handle the error
        }
    });
});

Input

In this example, we're filtering notifications by their source using the triggers string. Other filters include:

  • Show Read: Set to true to include previously read notifications.

  • Priority: Fetch notifications of a specific priority.

  • Of Type: Fetch notifications of a specific type, such as PullRewardAcquired for triggers and purchased items. If there are many notifications, use pagination to navigate through the data.

Mark as read

Once a notification is processed in your game logic, mark it as read. This will exclude it from future requests unless you specifically request read notifications. This action should be applied to each item in the list of handled notifications.

Logic for handling Notifications

When listing notifications, branch the completed event based on the success flag and add error handling for failed requests.

Note on Pagination: The notification response includes pagination data to help you navigate large notification lists.

We recommend branching the completed event from listing notifications on the success flag, and if you do this you will probably want to add error handling in case the request fails.

Here, we retrieve only unread notifications from the triggers source with default pagination (up to 10 items). We then filter further by SuccessfullyInvokedTriggerKey to narrow the list to specific triggers.

In this example, we simply print the notification info. Adapt this step to handle notifications based on your game’s requirements. Here, we assume that SuccessfullyInvokedTriggerKey provides a currency reward and only expand that information.

For a more general approach, iterate over all notifications to handle various sources and rewards relevant to your game.

curl --location --request GET 'https://api.lootlocker.io/game/notifications/v1?per_page=10&page=1' \
--header 'x-session-token: 3266edd928f5769545425469ac417fee456d8367' \

curl --location --request PUT 'https://api.lootlocker.io/game/notifications/v1/read' \
--header 'x-session-token: 3266edd928f5769545425469ac417fee456d8367' \
--header 'Content-Type: application/json' \
--data-raw '{
    "notifications": [
"01J6VYWY115186HY5N87HQDEC0",
"01J6VYWY0S1Z0MKKP9MTA8WZKB",
"01J6VYWY0F1MJ6E7QS93PZ4TQ7"
    ]
}'

It is important to mark notifications as read after you have taken action on it, otherwise you will need to go through all notifications each time, which increases response times, resulting in a bad experience for your players.

Conclusion

In this How-to, we’ve listed a notification and marked it as read. Notifications are to be called after a or after an invoked .

⛓️
trigger
catalog item
An active Game Session
invoked trigger
successful purchase
purchase has been made
trigger
Blueprint example of how to list notifications and subsequently mark the handled notifications as read. To copy the example, see .
Blueprint example of how to list notifications and subsequently mark the handled notifications as read. To copy the example, see .
Blueprint example of how to extract reward information from a notification. To copy the example, see .
https://blueprintue.com/blueprint/8wa1wn-m/
https://blueprintue.com/blueprint/m9x3-yjs/
https://blueprintue.com/blueprint/kx16g174/