question

Nguyen Hy Nhan avatar image
Nguyen Hy Nhan asked

How to use server.UpdateUserInventoryItemCustomData properly

Hello PlayFab.

This is my Cloud Script function:

handlers.UpdateCustomDataFishInInventory = function (args){
    if(!args || !args.ItemInstanceId|| !args.Data)
        throw "Invalid input parameters, expected ItemInstanceId";
    
    return server.UpdateUserInventoryItemCustomData({
        PlayFabId: currentPlayerId,
        ItemInstanceId: args.ItemInstanceId,
        Data: args.Data
    });
}

And this is the result after I executed the Cloud Script:

I don't want to save to PlayFabId & ItemInstanceId. I just want to save each key and value of Data.

How do I do this? Thanks.

sdks
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

My assumption of this issue is that the request is not well-formatted, moreover, there can be misunderstanding on our documentation and the Data property of the request can only accept a Dict<string, string>. Since the contents in "args.Data" is not given. I hope you may try to format it before sending the request.

You may also refer to https://community.playfab.com/questions/35409/updatecharacterreadonlydata-adding-unwanted-data-t.html and just want you to know that our documentation team has been working on it to correct the vague parts. I will inform the team if the request of UpdateUserInventoryItemCustomData is also involved.

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.

Nguyen Hy Nhan avatar image Nguyen Hy Nhan commented ·

Thank you SethDu. After I converted Data to Dictionary <string, string> instead of JSONObject, the data was saved to CustomData in the structure I wanted. Not only that, then the fields PlayFabId and ItemInstanceId also no longer appear in CustomData. I am satisfied with that.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Nguyen Hy Nhan commented ·

Thanks for the feedback. I believe this is another place on the documentation that needs a fix. I will mark this thread as closed and report to the team shortly.

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.