question

Dylan Hunt avatar image
Dylan Hunt asked

AddVirtualCurrency - I think I found a doc mistake (+not working for me)

TL;DR 1) I can't get AddVirtualCurrency to work. Maybe it's because I originally named my currency "gp" instead of "GP"? 2) "Amount" may be "AmountValue", looking at the error return?

___________________________________________

I was testing a simple function for adding currency, and realized when testing the server returns (below). I realized the message says "AmountValue" rather than "Amount" on the doc here:

https://api.playfab.com/documentation/Server/method/AddUserVirtualCurrency

I also realized that the currency now says "UPPERCASE" 2 letters. I can't change it -- when I first added it about 8 months ago, it was "gp". Would this be a reason of fail? The error is too generic.

The request from user's profile:

{
  "PlayFabId": "E123456789",
  "VirtualCurrency": "GP",
  "Amount": 100
}

I've tried both "gp" and "GP" (says "gp" in my dashboard, but also says uppercase)

The error is pointing here:

var addUserVirtualCurrencyResult = server.AddUserVirtualCurrency(addGpRequest);

{
    "FunctionResult": null,
    "Logs": [
        {
            "Level": "Debug",
            "Message": "{\"PlayFabId\":\"E123456789\",\"VirtualCurrency\":\"GP\",\"AmountValue\":50}",
            "Data": null
        },
        {
            "Level": "Error",
            "Message": "PlayFab API request error",
            "Data": [
                .............
    ],
    "ExecutionTimeSeconds": 0.0316734,
    "MemoryConsumedBytes": 28256,
    "APIRequestsIssued": 1,
    "HttpRequestsIssued": 0,
    "Error": {
        "Error": "CloudScriptAPIRequestError",
        "Message": "The script called a PlayFab API, which returned an error. See the Error logs for details.",
        "StackTrace": "Error\n    at handlers.addGold (77C6-CloudScript.js:30:47)"
    }
}
CloudScript
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

·
brendan avatar image
brendan answered

Sorry, but I'm not seeing anywhere in our documentation where we use "AmountValue" - it's not on the page you linked, as far as I can see. Can you provide more details on that?

We now require all newly created VCs to be capital letters, yes. We made that change a few months back, as we found there would be an issue if you had two VCs that were only different by capitalization (so, "gp" and "GP"). If you have an older title with lower-case VC defined though, you should continue to use them as lower-case in your calls (so, in your case, use "gp").

By the way, the best way to determine the details of an error in a call to a Server API method in a Cloud Script handler would be to put the call in a try, and in the catch, to log the error message.

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.

Dylan Hunt avatar image Dylan Hunt commented ·

Ahhhh I know what I was doing, I changed it, tested with an old revision (forgot to change it to live), then thought the return was actually a PF msg, but it was my own msg (just an old one when I accidentally put AmountValue). So I updated my script again to the OLD one that messed up, AmountValue, and REMEMBERED to update the revision.

TL;DR: All kinds of lack-of-caffeine idiocy on my end.

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.