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()); }
Answer by Sarah Zhang · Mar 09, 2020 at 03:08 AM
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; };
And how will I be sending an Array from my C# code in ExecuteCloudScript function?
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]" }, } };
Advantages of CloudScript over Calling JavaScript from Node.js 1 Answer
No confirmation email is received. 5 Answers
There is a problem with the certificate when using the container. 1 Answer
Azure Functions - context return null, Scheduled Tasks faild [two questions] 3 Answers
No CloudScript functions can be found,No CloudScript functions found 1 Answer