question

Lionserver avatar image
Lionserver asked

How can I revoke multiple items in RevokeInventoryItems?

Hello!! I use List<RevokeInventoryItem> RevokeList in PlayFabServerAPI.RevokeInventoryItems.

I add 3 items in RevokeList but it has error {duplicate item detected in request}.

How can I revoke multiple items in RevokeInventoryItems?

Thanks a lot!!

apis
10 |1200

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

Sarah Zhang avatar image
Sarah Zhang answered

@Lionserver Since you only used one instance AAA to store ItemInstanceIds, finally you repeatedly added "Moon-Face-01" to the array. You can use this method to check them.

 foreach (var item in RevokeList)
        {
            Debug.Log(item.ItemInstanceId + item.PlayFabId);
        }

Besides, ItemInstanceId (the inventory item instance's Id) should be a hex-encoded number, it seems what you fill in is the ItemId (the catalog item's Id). To retrieve the corresponding ItemInstanceId via itemId, you need to call the API GetUserInventory for players. The code can be something like this.

public class RevokeItems : MonoBehaviour
{
    public string PlayfabId;
    private List<RevokeInventoryItem> RevokeList;
   
    void Start()
    {
        PlayfabId = "[YourPlayFabID]";
        PlayFabServerAPI.GetUserInventory(new GetUserInventoryRequest { PlayFabId = PlayfabId }, OnGetSuccess, OnFailure);
    }
    private void OnGetSuccess(GetUserInventoryResult result)
    {
        var inventory = result.Inventory;
        List<ItemInstance> itemInstanceList = inventory.FindAll(ItemInstance => ItemInstance.ItemId == "Moon-Face-01"|| ItemInstance.ItemId == "Moon-Face-00");
        RevokeList = new List<RevokeInventoryItem>();
        foreach (var item in itemInstanceList)
        {
            Debug.Log(item.ItemInstanceId);
            RevokeList.Add(new RevokeInventoryItem { ItemInstanceId = item.ItemInstanceId, PlayFabId = PlayfabId });
        }
        PlayFabServerAPI.RevokeInventoryItems(new RevokeInventoryItemsRequest { Items = RevokeList }, OnRevokeSuccess, OnFailure);
    }
    private void OnRevokeSuccess(RevokeInventoryItemsResult obj)
    {
        Debug.Log("Success");
    }
    private void OnFailure(PlayFabError error)
    {
        Debug.LogError(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.

Sarah Zhang avatar image
Sarah Zhang answered

We tested the API RevokeInventoryItems, it can work fine. In fact, if you write the same ItemInstanceId for two item entries, this error will occur. Could you please check your ItemInstanceId?

If you use the different item instance ids for every item entry, but the issue still exists. Could you provide your development platform, and provide the detailed code?

2 comments
10 |1200

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

Lionserver avatar image Lionserver commented ·
revokeinventoryitems.zip

I still have problem...

This is my code and I check there are not the same ItemInstanceId.

Please help meQQ
0 Likes 0 ·
kb1nq.png (17.4 KiB)
Sarah Zhang avatar image Sarah Zhang Lionserver commented ·

Thanks for the reply. We will check it.

0 Likes 0 ·
Lionserver avatar image
Lionserver answered
using System.Collections.Generic;
using PlayFab;
using PlayFab.ServerModels;
using UnityEngine;


namespace HutongGames.PlayMaker.Actions
{
    public class PPFabRevokeInventoryItems : FsmStateAction
    {
        public FsmString PlayfabId;


        [UIHint(UIHint.Variable)]
        [ArrayEditor(VariableType.String)]
        public FsmString MyItemInstanceId;


        private List<RevokeInventoryItem> RevokeList;
        private RevokeInventoryItem AAA;


        public FsmEvent successdEvent;
        public FsmEvent failureEvent;


        public override void Reset()
        {
            PlayfabId = null;
            MyItemInstanceId = null;


        }
        public override void OnEnter()
        {
            RevokeList = new List<RevokeInventoryItem>();
            AAA = new RevokeInventoryItem();
            RevokeList.Clear();


            AAA.ItemInstanceId = "Moon-Face-00";
            AAA.PlayFabId = PlayfabId.Value;
            RevokeList.Add(AAA);
            AAA.ItemInstanceId = "Moon-Face-01";
            AAA.PlayFabId = PlayfabId.Value;
            RevokeList.Add(AAA);


            PlayFabServerAPI.RevokeInventoryItems(new RevokeInventoryItemsRequest {
                Items = RevokeList
            }, 
            result => {
                Debug.Log("Revoke Items succeed!!");
                Fsm.Event(successdEvent);
            }, 
            error => {
                Debug.LogError(error.GenerateErrorReport());
                Fsm.Event(failureEvent);
            });
        }
    }
}
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.