question

joel-3 avatar image
joel-3 asked

Get all groups player is in, through client cloudscript

Hey, this might be a dumb question but I am yet to find a way for a member of a group to access shared group data, without knowing the groupID first.

I get the ID is needed as they could be in many groups, my question is, how can I simply get the groups and IDs from cloudscript? If the player is logged in, can't I just fetch the groups like I can player data?

Similar to how server requests through cloudscript allow you to pass in the playerID for the current person logged in.

The goal is, upon logging in, a cloud script would run, checking if they're a valid subscribed customer.

Do I have to store the groupID in the player's Title data in order to do this?

I hope I have given enough information.

Shared Group Data
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

joel-3 avatar image joel-3 commented ·

All I need it to do is be able to have everyone in the group, upon log-in, be able to read a single value from the group data and use it to perform some additional checks we need.

I can't seem to find any cloud script snippets that show where I can get the groupID from, without somehow preemptively knowing it? If that makes sense. Every request requires the id to be passed through, but how can we know the ID of the group(s) they're in is my question? :)

0 Likes 0 ·

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

You can refer to the following summary of steps to implement that when players log in, they execute a CloudScript function to get the Groups (names and Ids) which they are in.

1. On the CloudScript in Revision 1, find a sample function whose name is makeEntityAPICall. Then duplicate it, modify the function name and change var apiResult = entity.SetObjects(…); into var apiResult = entity.ListMembership({Entity: entityProfile.Entity});, change return {…}; into return {Groups:apiResult.Groups};. In this step, please on the CloudScript use the entity API ListMembership to list all groups and roles for an entity.

2. Use the ExecuteEntityCloudScript API on the clients. In this step, please call this API after players successfully log in and provide the title_player_account type Entity in the request body.

3. Do some work to parse JSON on the clients.

Please click the links to check more API details. If you have any questions when you do it, feel free to let us know.

7 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.

joel-3 avatar image joel-3 commented ·

@Sarah Zhang Thanks for the reply! Ahh ok, I overlooked the EntityCloudScript API due to my search query, I was searching things like, 'Get GroupData from cloud script', and couldn't find any samples. Just might be something worth considering because I imagine others will be searching in a similar way so It might be worth adding snippets there :)

But again, thanks for getting back super quickly I will try this now!

0 Likes 0 ·
joel-3 avatar image joel-3 commented ·

@Sarah Zhang Do you have any examples for calling ExecuteEntityCloudScript from cloudscript? I tried simply calling makeEntityAPICall from the UI in playfab, however it requires context as a parameter, which is where the 'ExecuteEntityCloudScript clearly comes into play as it is where the data is passed in.

So how do I actually call it from cloud script? As all of this can happen in cloud script itself.

So I need cloud script that can be called from the UI, so essentially would wrap the API call for entity cloud script, because it happens on a user level, I should be able to get all the information required correct?

0 Likes 0 ·
playfaberror.png (43.3 KiB)
joel-3 avatar image joel-3 commented ·

I have tried this.

But this returns an empty array of groups?

Do I need to maybe use the Entity Token from post login? Or is there a way to access that if they are already logged in?

Just wondering if we are required to call this externally upon logging in, or if it can all be contained within cloudscript.

0 Likes 0 ·
attempt1.png (40.8 KiB)
Sarah Zhang avatar image Sarah Zhang joel-3 commented ·

We test it in the REST API testing tool Postman, it works fine. You can refer to the following CloudScript function and the request body.

handlers.makeEntityListMembershipAPICall = function (args, context) {

    var entityProfile = context.currentEntity;
    
    var apiResult = entity.ListMembership({
        Entity: entityProfile.Entity
    });
   
    return {
        Groups:apiResult.Groups
    };
};

request body -----------------------------------------------------------------


{
  "FunctionName": "makeEntityListMembershipAPICall",
  "FunctionParameter": {
   
  },
  "RevisionSelection": "Live",
  "GeneratePlayStreamEvent": true,
  "Entity": {
    "Id": "[the player title Id]",
    "Type": "title_player_account",
    "TypeString": "title_player_account"
  }
}
0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Sarah Zhang commented ·

Edited it for your case.

handlers.makeEntityListMembershipAPICallTest = function (args, context) {

    var entityProfile = args;

    var apiResult = entity.ListMembership({
        Entity: entityProfile.Entity
    });
  
    return {
        Groups:apiResult.Groups
    };
};

Arguments ----------------------------------------------------------------

{
  "Entity": {
    "Id": "[the player title Id]",
    "Type": "title_player_account",
    "TypeString": "title_player_account"
  }
}


0 Likes 0 ·
Show more comments

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.