question

Juris Zebnickis avatar image
Juris Zebnickis asked

Updating internal user data fails on cloudscript no matter the formatting and can't update the SDK

Hi!

So, firstly, I am definitely sure that this worked at some point before.

I noticed that my cloudscript is not working correctly after I tried updating the Unity PlayFab SDK. I just did not pay attention to it for a while.

So, that's where my problems began.

I tried updating it through the extension and manually, but the version always remains 2.116 and shows that it can be upgraded to 2.118. I found a few threads related to this issue, but no solution.

My guess is that the following issue might be a result of the version difference.

No matter how I format the data that I use for an internal user data update request on the cloudscript, the Data field is reported as empty and the request throws an error when executing like so:

{
    "EventName": "player_executed_cloudscript",
    "Source": "CloudScript",
    "FunctionName": "completedLevel",
    "CloudScriptExecutionResult": {
        "FunctionName": "completedLevel",
        "Revision": 48,
        "FunctionResult": null,
        "FunctionResultTooLarge": null,
        "Logs": [
            {
                "Level": "Error",
                "Message": "PlayFab API request error",
                "Data": {
                    "api": "/Server/UpdateUserInternalData",
                    "request": {
                        "PlayFabId": "D351F54068C9E532",
                        "Data": {}
                    },
                    "result": null,
                    "apiError": {
                        "code": 400,
                        "status": "BadRequest",
                        "retryAfterSeconds": null,
                        "error": "InvalidParams",
                        "errorCode": 1000,
                        "errorMessage": "Invalid input parameters",
                        "errorHash": null,
                        "errorDetails": {
                            "Data": [
                                "Must specify at least one of either Data or KeysToRemove."
                            ]
                        }
                    }
                }
            }
        ],
        "LogsTooLarge": null,
        "ExecutionTimeSeconds": 0.0162076,
        "ProcessorTimeSeconds": 0.004892,
        "MemoryConsumedBytes": 269512,
        "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 Object.server_request (Script:181:24)\n    at Object.server.UpdateUserInternalData (Script:628:79)\n    at handlers.completedLevel (A76EE-main.js:5:39)\n    at Object.invokeFunction (Script:117:33)"
        }
    },
    "EventNamespace": "com.playfab",
    "EntityType": "player",
    "TitleId": "A76EE",
    "EntityId": "D351F54068C9E532",
    "EventId": "9f8bd388418649ce894b754c68e5ab86",
    "SourceType": "BackEnd",
    "Timestamp": "2021-12-03T19:14:31.1240327Z",
    "History": null,
    "CustomTags": null,
    "Reserved": null,
    "PlayFabEnvironment": {
        "Vertical": "master",
        "Cloud": "main",
        "Application": "logicserver",
        "Commit": "1ef4dca"
    }
}

The cloud script function in question has been reduced to its' simplest possible version like so:

handlers.completedLevel = function (args, context) {
    var level = JSON.stringify(args.levelId);
    
    var updateUserDataResult = server.UpdateUserInternalData({
        PlayFabId: currentPlayerId,
        Data: {
            lastLevelCompleted: level
        }
    });
}

I have tried formatting the data in many different ways and tried all the examples from the example github. No luck.

Is this because the SDK is not updated or because of something else?

Please advise.

unity3dCloudScript
10 |1200

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

Seth Du avatar image
Seth Du answered

I reproduce this issue during my testing and the cause can be the incorrect API request.

Please double-check your API request and make sure levelId is defined in the "FunctionParameter" property. It should be like below:

{
  "FunctionName": "completedLevel",
  "FunctionParameter": {
    "levelId": 3
  },
  "RevisionSelection": "Live",
  "GeneratePlayStreamEvent": true
}

I suggest adding a value check condition in your cloud script function.

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.

Seth Du avatar image Seth Du ♦ commented ·

The URI that PlayFab Unity Extension uses to upgrade may not be updated. Though there is no major changes between 116 and 118 , if you look for the latest one, you may import from PlayFab/UnitySDK: Unity C# SDKs for PlayFab (github.com)

0 Likes 0 ·
Juris Zebnickis avatar image Juris Zebnickis Seth Du ♦ commented ·

Hi, Seth. Thank you, I tried that. It does not work and does not change anything.

0 Likes 0 ·
Juris Zebnickis avatar image
Juris Zebnickis answered

Ok it would seem that my data key was not matching between what I had in my request on Unity side and the one being looked for in the cloud script.

Other than that, we also managed to update our SDK, but we had to manually create the SharedPlayFabSettings object and copy it over to the path that it is looked for. We can also see that the diff from the version change in the SDK shows some path changes, so that must be what's tripping Unity up.

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.

JayZuo avatar image JayZuo ♦ commented ·

Sorry, there is an known issue with the Unity SDK, please see Cannot update from 2.116 to 2.120 when clicking upgrade button - Playfab Community.

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.