question

ignat-nee avatar image
ignat-nee asked

Entity Group default administrator by cloudscript

Greetings.
I'm trying to create new group for clan via cloudscript.

var groupApiResult = entity.CreateGroup({
		GroupName: clanName
    });

And it's created succesfully, but it's include only 1 member, which Entity type equals "title", and Entity Id equals my playfab project id (4 letters). Is there any possibility to create group by cloudscript with cusom administrator, as example with playfab id getted from arguments? If i call PlayFabGroupsAPI.CreateGroup from unity project by authorized user it's works correctly, with member type of "title_player_account", but i can't find out how to make it throught cloudscript.

Kind regards.

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

Entity API CreateGroup can designate a group administrator via defining the Entity field manually. You can refer to the API references and the following code. In addition, please pay attention to using ExecuteEntityCloudScript API on clients.

handlers.createGroup = function (args, context) {
    // The profile of the entity specified in the 'ExecuteEntityCloudScript' request.
    // Defaults to the authenticated entity in the X-EntityToken header.
    var entityProfile = context.currentEntity;
    // The pre-defined 'entity' object has functions corresponding to each PlayFab Entity API,
    var apiResult = entity.CreateGroup({
        Entity: entityProfile.Entity,
        GroupName: "Example Group01"
    });
    return {
        apiResult
    };
};
4 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.

ignat-nee avatar image ignat-nee commented ·

Thanks for answer.
I tried to wright such code:

var groupApiResult = entity.CreateGroup({
    Entity: {
        Id: currentPlayerId,
        Type: "master_player_account"
    },
    GroupName: clanName
});
But it won't work (returns me an error without explanation).
If i'm understood correctly, i'm try to create group with id of current player, which wrong, but i can't see how i can do this right.
0 Likes 0 ·
ignat-nee avatar image ignat-nee commented ·

Finally got it! When i'm call "entity.CreateGroup", i'm pass PlayFabId as entity Id. It's incorrect - you should pass entity, getted from "EntityToken", as example, you may try to call LoginWithServerCustomId, and get from result -> EntityToken -> Entity. Hope it's help someone someday.

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang ignat-nee commented ·

Congratulations. Thanks for your sharing. We will mark the answer for you. If you have any other questions, welcome to post a new question to discuss it with us.

0 Likes 0 ·
Enrico Paracchini avatar image Enrico Paracchini ignat-nee commented ·

I tried it doesn't work, would you have a code example?

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.