question

digitalmkt avatar image
digitalmkt asked

The best approach to get ItemInstanceId from a user inventory?

Hi, I'm trying the have the ItemInstanceId from a user inventory and then execute the OpenTradeRequest. When I try to get the OfferedInventoryInstanceIds it's returning an error . What I'm doing wrong? I just need a simple code to get the ItemInstanceId. Thank you very much.

The error:

Trading Not Opened/Client/OpenTrade PlayFabError(InvalidParams, Invalid input parameters, 400 BadRequest - Details: OfferedInventoryInstanceIds: Invalid Format | )

using the following code:

private void GetInventory()

    {

        Debug.Log("Starting Inventory Check");


        PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), OnApiCallSuccess, OnApiCallError);



    }



    private void OnApiCallSuccess(GetUserInventoryResult result)


    {

                GiveItemToMerchant();

    }



    private void OnApiCallError(PlayFabError error)

    {


    }



    public void GiveItemToMerchant()

    {

        string instanceID = new ItemInstance().ItemInstanceId;

       Debug.Log("Starting the Trading Item to Merchant: " + instanceID );


        PlayFabClientAPI.OpenTrade(new OpenTradeRequest()

        {

            AllowedPlayerIds = new List<string> { secondPlayerId }, // PlayFab ID for the friend who will receive your gift

            OfferedInventoryInstanceIds = new List<string> { instanceID } // The item instanceId fetched from GetUserInventory()

            //RequestedCatalogItemIds =  new List<string> { itemId } //The item instanceId fetched from GetUserInventory()

          

        }, tradeSuccesfull, tradeFailure);

    }
In-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

·
Seth Du avatar image
Seth Du answered

Can you print out "instanceID" after Line 40?

You may get instanceID after Line 19:

string instanceID = result.Inventory[0].ItemInstanceId

"Inventory" is a list contains all items and you can either re-construct it or adding them to GUI you designed so that player will directly click it.

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.

digitalmkt avatar image digitalmkt commented ·

Thanks. It works now and the OpenTrade was executed. The GetTradeStatus result is "open" but when trying to accept the trade the error now is the following: (from xcode): (I'm not using coroutines).

Thank you.

Error: TradeWaitForStatusTimeout

QRDecodeTest:HandleAcceptTradeError(PlayFabError)

PlayFab.Internal.PlayFabUnityHttp:OnResponse(String, CallRequestContainer)

PlayFab.Internal.<Post>c__Iterator1:MoveNext()

UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)


EDIT: I found that this error is because the tradeId wasn't synced with the userID (receiver). Everything is working fine now...

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.