question

ashburnbeau747@gmail.com avatar image
ashburnbeau747@gmail.com asked

How to use the filter string in PlayFabEconomyAPI.GetInventoryItems() in Unity.

I am developing a multiplayer game in Unity. I want to check if a player owns a specific inventory item using GetInventoryItems. I have the friendlyId of the object I want to check, and I think I can use the filter string on GetInventoryItems to make it only return that item. However, I cannot find any documentation on how the filter string works, so I figured I would come here to see if anyone more knowledgeable can either explain it (how to use the filter string in the GetInventoryItemsRequest) or link some documentation where I can learn what I need to know.

unity3dIn-Game Economy
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

Please note that the API GetInventoryItems does not support filtering with "FriendlyId". Currently, only 'type', 'id', 'stackId' and 'eq' are supported in this API’s request parameter “Filter”. If you want to use “FriendlyId” to check if a player has a specific item in his inventory, then as a workaround, you can call API GetItems to get the item id through FriendlyId first, then call API GetInventoryItems and filter with item id to check if player has this item. Or you can call the API SearchItems to cache the entire catalog first, then you only need to call the API GetInventoryItems once. In addition, you can refer to Search - PlayFab | Microsoft Learn for more info about using filter. You can also refer to my test code below.

 public void TestGetInventoryItemsAndFilter()
     {
         PlayFabEconomyAPI.GetInventoryItems(new GetInventoryItemsRequest()
         {
             Filter = "id eq 'c41dc5ca-6fbf-4a41-xxxx-xxxxxxxxxxx'"
         },
     result => {
         if (result.Items == null ) Debug.Log("The player does not own this item");
         else Debug.Log("The player owns this item");
     },
     error => {
         Debug.Log("Get error");
         Debug.Log(error.GenerateErrorReport());
     });
     }
10 |1200

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

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.