question

romagoldun avatar image
romagoldun asked

How can I get catalog items, player inventory and player currency in V2? Unity + C#

Could you give code examples please?

In-Game EconomyPlayer Inventory
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Neils Shi avatar image
Neils Shi answered

Players can call API SearchItems to execute a search against the public catalog using the provided search parameters. For more info, you can refer to https://learn.microsoft.com/en-us/gaming/playfab/features/economy-v2/quickstart?tabs=secret-key-api%2Ccatalog-settings-game-manager%2Cpublish-item-game-manager%2Csearch-game-manager%2Cvirtual-currency-game-manager%2Cgrant-currency-game-manager%2Ccreate-catalog-item-game-manager#step-4---do-a-search. The currency in Economy V2 is also an item, and players can use the API GetInventoryItems with the request parameter "Filter" to specify what type of item they want to retrieve. For more info, please refer to https://learn.microsoft.com/en-us/gaming/playfab/features/economy-v2/inventory/?tabs=inventory-api#getting-a-players-inventory. And you can also refer to my testing code examples below:

 public void SearchItemsTest()
     {
         PlayFabEconomyAPI.SearchItems(new PlayFab.EconomyModels.SearchItemsRequest()
         {
             Count = 10
         },
    result => {
        Debug.Log("Search items successfully");
        foreach (var item in result.Items)
        {
            Debug.Log("Item ID:"+ item.Id);
            //Print out the searched item id
        }
    },
    error => {
        Debug.Log("Got error searching items");
        Debug.Log(error.GenerateErrorReport());
    });
     }
    
     public void RetrieveInventoryTest()
     {
         PlayFabEconomyAPI.GetInventoryItems(new PlayFab.EconomyModels.GetInventoryItemsRequest()
         {
             Count = 10,
             Filter = "type eq 'currency'"
         },
    result => {
        Debug.Log("Retrieve inventory items successfully");
        foreach (var item in result.Items)
        {
            Debug.Log("Item ID:" + item.Id);
            //Print out the retrieved item id
        }
    },
    error => {
        Debug.Log("Got error");
        Debug.Log(error.GenerateErrorReport());
    });
     }
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

romagoldun avatar image romagoldun commented ·

Thank you!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.