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).
Answer by Ricardo Chavarria · Feb 23, 2018 at 03:47 AM
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.
Answer by Brendan · Feb 21, 2018 at 06:56 AM
Sorry, but can you clarify how you're making this call specifically? Having the code snippet showing the actual Cloud Script would help.
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); } ... }
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))
Will do. It just seems a bit weird that this exact code is working on our other titles and not this one.
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.
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
Answer by Ricardo Chavarria · Feb 22, 2018 at 04:48 AM
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." ] } } } } ],