question

Ricardo Chavarria avatar image
Ricardo Chavarria asked

CloudScript UpdateUserReadOnlyData Error

Hi,

I'm getting an error when updating `UserReadOnlyData` from CloudScript

{
    "api": "/Server/UpdateUserReadOnlyData",
    "request": {
        "PlayFabId": "94CBFE4872721A3B",
        "Data": {
            "FirstSessionDate": "02/21/2018 05:06:27"
        }
    },
    "result": null,
    "apiError": {
        "code": 400,
        "status": "BadRequest",
        "error": "InvalidParams",
        "errorCode": 1000,
        "errorMessage": "Invalid input parameters",
        "errorHash": null,
        "errorDetails": {
            "Data": [
                "The value for key FirstSessionDate was not valid JSON."
            ]
        }
    }
}

This is the same code I'm using in all my previous titles, which should work for this title as well (589A).

10 |1200

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

Ricardo Chavarria avatar image
Ricardo Chavarria answered

Ok, so the answer is, there IS something different with other titles, and that's the Settings > API panel has this option: Require valid JSON for custom data values.

This option must have been added as default on for new titles, because it was OFF for old titles and ON for this new one.


We'll have to check our procedures and see what is not valid JSON, but turning this OFF fixed our problems for now.


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

Sorry, but can you clarify how you're making this call specifically? Having the code snippet showing the actual Cloud Script would help.

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.

Ricardo Chavarria avatar image Ricardo Chavarria commented ·

Here's the code:

function SetReadOnlyData(data)
{
    var request = {
        "PlayFabId": currentPlayerId,
        "Data": data
    };


    var result = server.UpdateUserReadOnlyData(request);
    var dataVersion = result.DataVersion;
    var readonlyData = server.GetUserReadOnlyData({"PlayFabId": currentPlayerId});


    var response = {
        "DataVersion": dataVersion,
        "ReadOnlyData": readonlyData.Data
    };


    return response;
}

Which is called from here:

handlers.onAccountCreation = function(args)
{
    var firstSessionDate = args.firstSessionDate;

...

    // Readonly data
    if (firstSessionDate != null)
    {
        var data = {
            "FirstSessionDate": firstSessionDate
        };


        response["ReadOnlyData"] = SetReadOnlyData(data);
    }


...



}
0 Likes 0 ·
Joshua Strunk avatar image Joshua Strunk commented ·

Can you add a log before you make the request which prints out the value of the data object you are trying to set?

As the first line of your SetReadOnlyData function

log.info(JSON.stringify(data))
0 Likes 0 ·
Ricardo Chavarria avatar image Ricardo Chavarria Joshua Strunk commented ·

Will do. It just seems a bit weird that this exact code is working on our other titles and not this one.

0 Likes 0 ·
Ricardo Chavarria avatar image Ricardo Chavarria Joshua Strunk commented ·

This is from one of our other titles, a user created yesterday. I don't get why the same code would behave differently in this title.

0 Likes 0 ·
Joshua Strunk avatar image Joshua Strunk Ricardo Chavarria commented ·

Yea I am not sure but my guess is that in this case FirstSessionDate is not actually a string or it is a weird string trigging some edge case? It is hard to tell without the log

0 Likes 0 ·
Show more comments
Ricardo Chavarria avatar image
Ricardo Chavarria answered

I still don't see the problem. This being used exactly the same in our production-titles, it makes little sense.

"Logs": [
            {
                "Level": "Info",
                "Message": "{\"FirstSessionDate\":\"02/22/2018 04:39:13\"}",
                "Data": null
            },
            {
                "Level": "Error",
                "Message": "PlayFab API request error",
                "Data": {
                    "api": "/Server/UpdateUserReadOnlyData",
                    "request": {
                        "PlayFabId": "94CBFE4872721A3B",
                        "Data": {
                            "FirstSessionDate": "02/22/2018 04:39:13"
                        }
                    },
                    "result": null,
                    "apiError": {
                        "code": 400,
                        "status": "BadRequest",
                        "error": "InvalidParams",
                        "errorCode": 1000,
                        "errorMessage": "Invalid input parameters",
                        "errorHash": null,
                        "errorDetails": {
                            "Data": [
                                "The value for key FirstSessionDate was not valid JSON."
                            ]
                        }
                    }
                }
            }
        ],
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.