This how-to fetches Metadata matching a specific key from multiple items in a single request.
Prerequisites
- Unity, Unreal, or Godot SDK installed and configured in your project (not required for REST).
- An active Player session (see Authentication).
- A feature with at least one type of Metadata configured (see Add Metadata in Console).
Fetch Metadata from Multiple Sources
When fetching Metadata from multiple sources, provide three things for each source:
- A
ulid: the ID of the item to fetch Metadata for. This can be retrieved through the Web Console or in the SDKs, depending on the feature.- For example:
01J96M0BX1GGTPP2QDRCBV3FW2
- For example:
- A key: the key of the desired Metadata entry.
- For example:
icon
- For example:
- A source type: one of the following: Progression, Leaderboard, Catalog Item, or Currency.
A key supersedes tags, so if you want to search by tags, it's best to avoid using keys and vice versa.
// Create an array of sources and keys that we want to fetchLootLockerMetadataSourceAndKeys[] sourcesAndKeys = new LootLockerMetadataSourceAndKeys[]{ new LootLockerMetadataSourceAndKeys { source = LootLockerMetadataSources.currency, id = "01J7S0CED5K0THCB1ENN9XKQWZ", keys = new string[] { "icon" } }, new LootLockerMetadataSourceAndKeys { source = LootLockerMetadataSources.catalog_item, id = "01J9RE51T32WNXSQADNJ5RGQCX", keys = new string[] { "icon", "featured" } }};
// Base64 can be set to content_type "application/x-redacted", use this to avoid accidentally fetching large data filesbool ignoreFiles = true;
LootLockerSDKManager.GetMultisourceMetadata(sourcesAndKeys, (response) =>{
if (response.success) { // Handle the received metadata differently depending on the use cases foreach (var entry in response.Metadata) { // Currency if (entry.source == LootLockerMetadataSources.currency) { // Get the first entry as a base64 (file), this is an image so we convert it to a sprite to be displayed LootLockerMetadataBase64Value base64String = null; entry.entries[0].TryGetValueAsBase64(out base64String); byte[] imageBytes = Convert.FromBase64String(base64String.content); Texture2D tex = new Texture2D(291, 302); tex.LoadImage(imageBytes); tex.filterMode = FilterMode.Point; Sprite sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f); // Add your own code here to display the sprite }
// Catalog Item if (entry.source == LootLockerMetadataSources.catalog_item) { // Multiple keys requested: loop through to find the correct one foreach (var catalogItemMetadata in entry.entries) { // Handle the image if (catalogItemMetadata.type == LootLockerMetadataTypes.Base64) { // Look above in how LootLockerMetadataSources.currency is handled to see how to handle an image }
// Handle a bool if (catalogItemMetadata.type == LootLockerMetadataTypes.Bool) { bool featured = catalogItemMetadata.TryGetValueAsBool(out featured); // Add your own code here to make us of the returned bool value } } } } } else { // If it failed, output the error to the console Debug.Log(response.errorData.message); }}, ignoreFiles);Coming soon — this sample hasn't been written yet. In the meantime, refer to the Reference Documentation for this endpoint.
Coming soon — this sample hasn't been written yet. In the meantime, refer to the Reference Documentation for this endpoint.
curl --location --request POST 'https://api.lootlocker.io/game/metadata/multisource?ignore_files=true' \--header 'x-session-token: your_token_here' \--header 'Content-Type: application/json' \--data-raw '{ "sources": [ { "source": "leaderboard", "id": "01J8030AMYTZN4ZQ4WBT3V8XGP", "keys": [ "has_beta_access", "preferred_nickname" ] }, { "source": "catalog_item", "id": "01J7S0CED5K0THCB1ENN9XKQWZ", "keys": [ "has_beta_access" ] } ]}'Conclusion
You've fetched multiple Metadata entries created in the Web Console from multiple sources in a single request. You can also fetch a single Metadata entry or Metadata by tags.