question

runbycoffee avatar image
runbycoffee asked

TradeDoesNotExist

API Call Results
{
 "code": 200,
 "status": "OK",
 "data": {
  "Trade": {
   "Status": "Open",
   "TradeId": "B4AFB68C4CA85DFF",
   "OfferingPlayerId": "FBA03846D482A778",
   "OfferedInventoryInstanceIds": [
    "7141375AF4A7038A"
   ],
   "OfferedCatalogItemIds": [
    "girl-hair-02"
   ],
   "AllowedPlayerIds": [
    "FBA03846D482A778",
    "7E7095808E3218BC"
   ],
   "OpenedAt": "2017-08-23T17:36:51.907Z"
  }
 },
 "CallBackTimeMS": 470
}

TitleID: EFA2

TradeID: B4AFB68C4CA85DFF
Player who opened trade: FBA03846D482A778
Send to player: 7E7095808E3218BC

How?

We use normal "OpenTrade", like so:

OpenTradeRequest requesti = new OpenTradeRequest();

List<string> items = new List<string>();
esineet.Add(lahja); (iteminstanceID)

List<string> TradePersons = new List<string>();
TradePersons.Add(FBMana.pf_uid); (playfabID for player who is sending item)
TradePersons.Add(kaveri_id); (playfabID for player who receives item)

requesti.OfferedInventoryInstanceIds = items;
requesti.AllowedPlayerIds = TradePersons;
PlayFabClientAPI.OpenTrade(requesti, Onnistunut, OnPlayFabError);

After that I launch cloud script function as follow:

handlers.LisaaTradi = function(args) {
    
    var str = args;
      var pid = str.split(":")[0];

      var GetUserData  = server.GetUserData ({
    PlayFabId: pid,
    Keys: ["Trading_Lista"]
    });
      
      var TradingID = GetUserData.Data["Trading_Lista"].Value;
    if (TradingID.length < 4) {
        var updateUserDataResult = server.UpdateUserData({
        PlayFabId: pid,
            Data: { Trading_Lista: str.split(":")[1]}
        });
    }
  
      else {
        var updateUserDataResult = server.UpdateUserData({
        PlayFabId: pid,
            Data: { Trading_Lista: TradingID+","+str.split(":")[1]}
        });
    }
};

In short, we save TradeID to receiving player UserData in field "Trading_Lista", if list has nothing, we use black magic to correct so that first TradeID is always in correct format (this works, even if me explaining does not).

Then we player (who is receiving these items) wants to check in-game, we call simple function

        string tradetukset = result.Data["Trading_Lista"].Value;
        string[] splittaa = tradetukset.Split(',');
        for (int t = 0; t < splittaa.Length; t++)
        {
            GameObject paita = Instantiate(Resources.Load("TavaraLahja") as GameObject);
            Debug.Log(splittaa[t]);
            paita.transform.SetParent(LahjatGrid.transform);
            paita.GetComponent<TavaraDetails>().vaihtoID = splittaa[t];
            paita.transform.name = splittaa[t];
            paita.transform.localScale = new Vector3(1, 1, 1);
        }

In short, this turns UserData field "Trading_Lista" into single Trading ID's for us to loop, such as

1) 9722405FBA39A518,31EE04F1DB4A0CE0

2) AAD79A8604313835,F866068A2D270DEC

3) 5A3FD4E9BD2E15F2

etc...

All the trading ID's are correct, made sure by using https://api.playfab.com/documentation/client/method/GetTradeStatus and "try api", all sends "Ok" status.

After user clicks gift icon, we launch yet another function

    public void HyvaksyLahja (string TradeID_ToApprove)
    {
        AcceptTradeRequest approved_trade = new AcceptTradeRequest();
        approved_trade.TradeId = TradeID_ToApprove;
        PlayFabClientAPI.AcceptTrade(approved_trade TradeConfirm, OnPlayFabError);
    }

but with last function, we get always error "TradeDoesNotExist".

1) TradeID and player PlayFabID's are correct.

2) Correct items (and ItemID) are send, as they are removed from player inventory as they should.

3) I can see trade I opened fine.

4) I can successfully loop opentrades for players who is receiving them, with correct TradingID's.

5) Player who is supposed to receive my gift, cant open them due to "TradeDoesNotExist" error.

Hopefully any of this made sense.

10 |1200

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

brendan avatar image
brendan answered

I'm assuming the missing comma after approved_trade in the AcceptTrade call is just a typo in this post?

If so, can you please put a breakpoint in your code where AcceptTrade is called, and confirm what the ID is that's being passed in?

4 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.

runbycoffee avatar image runbycoffee commented ·

Correct, it was typo, code is working as intended (minus the part about trade not existing).

Approving happens here:

public void HyvaksyLahja (string TradeID_ToApprove)
{
Debug.Log("Ready to approve trade: : " + TradeID_ToApprove);
AcceptTradeRequest approved_trade = new AcceptTradeRequest();
approved_trade.TradeId = TradeID_ToApprove;
PlayFabClientAPI.AcceptTrade(approved_trade TradeConfirm,OnPlayFabError);
}

Debug message prints:

Ready to approve trade: : B4AFB68C4CA85DFF

Using via:

https://api.playfab.com/documentation/client/method/GetTradeStatus

1) OfferingPlayerId: FBA03846D482A778
1) TradeID: B4AFB68C4CA85DFF

{
 "code": 200,
 "status": "OK",
 "data": {
  "Trade": {
   "Status": "Open",
   "TradeId": "B4AFB68C4CA85DFF",
   "OfferingPlayerId": "FBA03846D482A778",
   "OfferedInventoryInstanceIds": [
    "7141375AF4A7038A"
   ],
   "OfferedCatalogItemIds": [
    "girl-hair-02"
   ],
   "AllowedPlayerIds": [
    "FBA03846D482A778",
    "7E7095808E3218BC"
   ],
   "OpenedAt": "2017-08-23T17:36:51.907Z"
  }
 },
 "CallBackTimeMS": 464
}

AllowedPlayerID's are correct in that respons, as "7E7095808E3218BC" is player trying to approve trade opened by "FBA03846D482A778".

0 Likes 0 ·
brendan avatar image brendan runbycoffee commented ·

That trade is stuck in the Accepting status, which is normally a short-lived status which the trade should only be in while the items are being finalized between players. Are you able to reproduce this issue? If so, can you specifically give me only the sequence of API calls made, with the parameters?

0 Likes 0 ·
runbycoffee avatar image runbycoffee brendan commented ·

I dont get status (unless I try from docs "try" button).

Here are important parts only dealing with approving setup.


1) GET USERDATA FOR LOOP

public void GetLoopData ()
{
GetUserDataRequest request = new GetUserDataRequest();

PlayFabClientAPI.GetUserData(request, LoopItems, OnPlayFabError);
}

== FUNCTION TO LOOP AND ATTACH TRADE_ID FOR EACH ICON ==

Now I get icons for each Trade ID, script is attached them with only param being Trade_ID.

Example: I clicked now icon, I get "B4AFB68C4CA85DFF" as trading ID, now we pass it to Set_TradeID


2) SETUP TRADE ID

When icon is clicked, we get Trade_ID from script attached to icon.

public void Set_TradeID (string Trade_ID)
 {  
Debug.Log("Ready to approve trade: : " + Trade_ID);

AcceptTradeRequest request = new AcceptTradeRequest();

request.TradeId = Trade_ID;

PlayFabClientAPI.AcceptTrade(request, ApproveTrade, OnPlayFabError);
 }


3) FINALLY, APPROVE TRADE

public void ApproveTrade (AcceptTradeResponse result)
{
Debug.Log("Completed trade with ID: " + result.Trade.TradeId);
}
0 Likes 0 ·
Show more comments
runbycoffee avatar image
runbycoffee answered

Seems I can't reply to last comment, not getting "reply" link anymore.

Sadly I'm not familiar with either those services,

I tried this: https://api.playfab.com/documentation/client/method/AcceptTrade (try it button)

Title ID: EFA2 (API endpoint: https://efa2.playfabapi.com)

OfferingPlayerId: FBA03846D482A778

TradeId: B4AFB68C4CA85DFF

This results into TimeOut.


API Call Results

{
 "code": 400,
 "status": "BadRequest",
 "error": "TradeWaitForStatusTimeout",
 "errorCode": 1164,
 "errorMessage": "TradeWaitForStatusTimeout",
 "CallBackTimeMS": 6902
}

So only part where trading API comes to picture is final part:

public void Set_TradeID (string Trade_ID)
{  
AcceptTradeRequest request = new AcceptTradeRequest();
request.TradeId = Trade_ID;

PlayFabClientAPI.AcceptTrade(request, ApproveTrade, OnPlayFabError);
 }

Trade_ID is correct, I confirmed this multiple times with debug messages. Apologies if this starts to get too confusing, I'm not sure why we are getting time outs, as far I can see, only step where we use trading API is one function where I simply pass TradeID as string.

6 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.

brendan avatar image brendan commented ·

I'm not sure what "either of those services" refers to - the recommendation was to get a Wireshark capture - the link above is for the site where you can download that tool and get access to all the documentation on how to use it. I highly recommend it - it and Postman are two of the most valuable tools there are for debugging online functionality.

My point above was that this one specific trade is in a bad state - no others are in your title. So I would like to find out how it got into this state. So continuing to use that trade is pointless, as what we need to understand is what the steps were you took that resulted in it being in this state. Can you please try with a new trade, and make note of each API call in the process and the specific parameters which were sent into each?

0 Likes 0 ·
runbycoffee avatar image runbycoffee brendan commented ·

Which services I meant to say, I have not used postman or Wireshark before (tools, services, progmans, scripts etc), but will look in those soon, thanks for the suggestions.

Seems problem is with all trades, just deleted all existing trades (with CancelTrade), created two new characters, purchased few items and did setup new trades between those two new characters, same results about trade not existing.

Before going further, few points:

  • I can see my OWN trades which I STARTED just fine, view details and even cancel them.
  • When I login with my another character (old or just created), I can see that I have trade open which was send by my main account with CORRECT trade ID.
  • Trade ID is correct, I save them to userdata, I checked them via debug messages (while we loop trade ID results).

I assume we are dealing with language barrier here.

I have created now over 8 trades, all returns same error (even with new player accounts).

Sadly I'm not sure if I explain things better in details. Everything works just before final part (Set_TradeID function mentioned in previous post), which is accepting trade using "PlayFabClientAPI.AcceptTrade" call.

0 Likes 0 ·
runbycoffee avatar image runbycoffee brendan commented ·

Quick update and another test:

public void AcceptTrade_Test ()

AcceptTradeRequest request = new AcceptTradeRequest();

request.TradeId = "AEAE0AEFE1A3CDB7";

request.OfferingPlayerId = "5627FEFECFAD49CF";

PlayFabClientAPI.AcceptTrade(request, ApproveDebug, OnPlayFabError);}

So this time no passing anything, I hardcoded Trade ID and offering player (just to make sure they are 100% correct). Now I get "TradeWaitForStatusTimeout" error , similiar to this:

https://community.playfab.com/questions/7728/accepttrade-always-giving-timeout-error.html (trades are not requiring item in return, they are gifts).

0 Likes 0 ·
brendan avatar image brendan runbycoffee commented ·

While I can see your trades in the service, I've yet to be able to reproduce your results, which is what I need to be able to debug this. All the trades I've created in my own test title are working fine, so I need specific information from you. Please create a new trade and proceed to the point where it's in this bad state, and make note of each step. Here's what I need you to tell me:

1. You call OpenTrade with what specific values for OfferedInventoryInstanceIds, RequestedCatalogItemIds, and AllowedPlayerIds, and what PlayFab ID is making the call? What is the Trade ID returned? If the result is anything other than OK, please provide complete details of the result. Please also note that I'm not asking for code snippets, but the actual values you are passing in.

2. You call AcceptTrade with what specific values for OfferingPlayerId, TradeID, and AcceptedInventoryInstanceIds? What PlayFab ID are you using to make this call?

Are you making any other calls, apart from login for these two player accounts at any time between these two calls? If so, what are the details of those calls and the parameters passed in?

0 Likes 0 ·
Show more comments

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.