question

Kim Strasser avatar image
Kim Strasser asked

CloudScript: How can I update more than one key value pair at once with UpdateUserReadOnlyData?

I get an error message when I want to update two key value pairs at once.

  "errorMessage": "Invalid input parameters",
                        "errorHash": null,
                        "errorDetails": {
                            "Data": [
                                "Must specify at least one of either Data or KeysToRemove."
                            ],
                            "PlayFabId": [
                                "The PlayFabId field is required."
                            ]
                        }
var addingData = [];
           
var MyRequest = {
                PlayFabId: currentPlayerId,
                Data: {},
                Permission: UserDataPermission.Private
                };
 
var keyname = "PlayerData";
var valuename = {"Timestamp":"28/02/2020","Title":"MyTitle","Message":"Hello."};
var valuejson = JSON.stringify(valuename);
MyRequest.Data[keyname] = valuejson;
addingData.push(MyRequest);
            
var MyRequest1 = {
                 PlayFabId: currentPlayerId,
                 Data: {},
                 Permission: UserDataPermission.Private
                 };
 
var keyname1 = "PlayerNumber";
var mynumber = 10;
MyRequest1.Data[keyname1] = mynumber;
addingData.push(MyRequest1);
            
var dataupdate = server.UpdateUserReadOnlyData(addingData);
log.info(dataupdate);

How can I update more than one key value pair at once when I use server API UpdateUserReadOnlyData?

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

·
Seth Du avatar image
Seth Du answered

PlayFab doesn't support submitting multiple requests as an array. If you want to update multiple player data, simply adding more KVP in Data property, for example:

MyRequest1.Data[keyname1]= mynumber;
MyRequest1.Data[keyname2]= mynumber2;
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.

Kim Strasser avatar image Kim Strasser commented ·

Thanx, it works now. I have a question about Permission. Is it possible to have different Permissions for each key value pair in MyRequest1? For example keyname1 has UserDataPermission.Private and keyname2 has UserDataPermission.Public?

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Kim Strasser commented ·

This cannot be done by single API call. If the permission is different, you have to make 2 separate calls, one is for public and the other is for private.

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.