question

Muhammad Roshaan Tariq avatar image
Muhammad Roshaan Tariq asked

How can I Remove member from Group/Clan using Cloudscript?

Hi,

I want to use cloudscript for removing members from group using this API. I have written a function using the best of my knowledge of Playfab's Cloudscripting

here's my cloud code:

handlers.leaveGroup = function(args,context){
  var removeGroupMember = {
      "Group":{
          "Id": args.groupID
      },
      "Members":{
          "Entity":{
              "Id": args.userID,
              "Type": "title_player_account",
              "TypeString": "title_player_account"
          }
      }
  };
  
  var response = entity.RemoveMembers(removeGroupMember);
  return response;
};

When I send the request from my game I get the response as NULL and I don't understand why it is happening.

here's my code from my game:

internal void LeaveGroup(string _groupID)
{
    requestCompleted = false;

    PlayFabAuthenticationAPI.GetEntityToken(new PlayFab.AuthenticationModels.GetEntityTokenRequest(), result =>
    {
        ExecuteCloudScriptRequest cloudCodeRequest = new ExecuteCloudScriptRequest
        {
            FunctionName = "leaveGroup",
            FunctionParameter = new
            {
                groupID = _groupID,
                userID = result.Entity.Id
            }
        };

        PlayFabClientAPI.ExecuteCloudScript(cloudCodeRequest, OnSuccessfulResponse, OnFailedResponse);
    }, OnFailedResponse);
}

private void OnSuccessfulResponse(ExecuteCloudScriptResult result)
{
    Debug.Log("Success");
    Debug.Log(result.FunctionResult);
}

private void OnFailedResponse(PlayFabError error)
{
    Debug.LogError("Error Report: " + error.GenerateErrorReport());
}
apissdksCloudScript
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

According to this API reference Remove Members, there is not a field whose name is “Entity” in the request body of this API and the value of field “Members” should be an array. Your CloudScript code should be the following one.

handlers.leaveGroup = function (args, context) {
    var removeGroupMember = {
        "Group": {
            "Id": args.groupID
        },
        //Remove "Entity{}", add "[]"
        "Members": [{
            
                "Id": args.userID,
                "Type": "title_player_account",
                "TypeString": "title_player_account"
            
        }]
    };

    var response = entity.RemoveMembers(removeGroupMember);
    return response;
};

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.

Muhammad Roshaan Tariq avatar image Muhammad Roshaan Tariq commented ·

@Sarah Zhang

And how will I be sending an Array from my C# code in ExecuteCloudScript function?

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Muhammad Roshaan Tariq commented ·

You can refer to the following code. Please refer to the C# documentation for more information about C# programming language.

  var executeCloudScriptRequest = new ExecuteCloudScriptRequest
        {
            FunctionName = "[YourFunctionName]",
            FunctionParameter = new { members = new string[] { "[YourPlayFabId01]", "[YourPlayFabId02]" }, }
        };

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.