question

Bernhard Hofer avatar image
Bernhard Hofer asked

Grant Character To User Server API

Hello,

I know I have asked yesterday for the same topic. I checked that I can add characters to player via Server Api and Client Api. For Server Api I have to use Cloud Scripts and execute it on Unity to get a character. But I have no plan for the documentation. Is there no example code ? On the old documentation I always saw a example code ..

https://docs.microsoft.com/en-us/rest/api/playfab/server/characters/grantcharactertouser?view=playfab-rest

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

·
Sarah Zhang avatar image
Sarah Zhang answered

You can refer to the following Cloud Script sample to write a function that invokes the server API GrantCharacterToUser. You can find many samples in the title’s default Cloud Script revision. For more detailed information about Cloud Script, please check the doc -- CloudScript. Besides, you can check this doc -- How to modify read-only or internal player data from CloudScript to learn how to execute the Cloud Script function via Client API ExecuteCloudScript.

handlers.grantCharacterToMe = function (args, context) {
    var request = {
        PlayFabId: currentPlayerId,
        CharacterName: "FighterDude",
        CharacterType: "Blue Warrior"
    };
    // The pre-defined "server" object has functions corresponding to each PlayFab server API 
    // (https://api.playfab.com/Documentation/Server). It is automatically 
    // authenticated as your title and handles all communication with 
    // the PlayFab API, so you don't have to write extra code to issue HTTP requests. 
    return server.GrantCharacterToUser(request);
};

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.