question

soloth avatar image
soloth asked

cloudscript : How do I add a player to a group

I am trying to add a player to a group via a call to ExecuteCloudScript.

Here's the handler I'm using :

handlers.addMember = function (args, context)
{
	var group = { Id: args.GroupId, Type: "group" };
	var member = { Id: currentPlayerId, Type: "title_player_account" };
 
	// Here is the logic that check if the player can join the group

	var result = entity.AddMembers({ Group: group, Members: [member] });
	return result;
}

Unfotunately it gives me a pretty generic error and I don't know where to go from there.

Thanks in advance for any help you can provide.

CloudScript
screenshot-1.png (3.5 KiB)
screenshot-2.png (6.5 KiB)
10 |1200

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

soloth avatar image
soloth answered

I finally managed to make it work. Here's the code for anyone interested.

handlers.addMember = function (args, context) 
{
	var group = { Id: args.GroupId, Type: "group" };
	var titlePlayerAccount = server.GetUserAccountInfo({ PlayFabId: currentPlayerId }).UserInfo.TitleInfo.TitlePlayerAccount;
 
	try
	{
		var result = entity.AddMembers({ Group: group, Members: [titlePlayerAccount] });
		log.info(JSON.stringify(result) );
	}
	catch (e)
	{
		var msg = "Error: " + JSON.stringify(e);
		log.info(msg);
	}
 
	return result;
}
10 |1200

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

soloth avatar image
soloth answered

After encompassing my the call to AddMembers in to a try-catch I got a more precise error :

Error:
{
  "cloudScriptErrorCode": "CloudScriptAPIRequestError",
  "stack": "Error\n\r\n    at Object.server_request (Script Document:178:24)\n\r\n    at Object.entity.AddMembers (Script Document:641:67)\n\r\n    at handlers.addMember (4310-main.js:49:23)\n\r\n    at Object.invokeFunction (Script Document:114:33)",
  "apiErrorInfo": {
    "api": "/Group/AddMembers",
    "request": {
      "Group": {
        "Id": "8A61F38CDB84FDE7",
        "Type": "group"
      },
      "Members": [
        {
          "Id": {
            "Id": "5D12DDF101F5E83D",
            "Type": "title_player_account",
            "TypeString": "title_player_account"
          },
          "Type": "title_player_account"
        }
      ]
    },
    "result": null,
    "apiError": {
      "code": 400,
      "status": "BadRequest",
      "error": "InvalidParams",
      "errorCode": 1000,
      "errorMessage": "Invalid input parameters",
      "errorHash": null,
      "errorDetails": {
        "EntityKey": [
          "Type or TypeString is required.",
          "Id is required.",
          " is not an allowed value of Type."
        ],
        "Group": [
          "Id is required."
        ]
      }
    }
  }
}

Here's my new code.

handlers.addMember = function (args, context) 
{
	var group = { Id: args.GroupId, Type: "group" };
	var playerTitleID = server.GetUserAccountInfo({ PlayFabId: currentPlayerId }).UserInfo.TitleInfo.TitlePlayerAccount;
	var member = { Id: playerTitleID, Type: "title_player_account" };
 
	try
	{
		var result = entity.AddMembers({ Group: group, Members: [member] });
		log.info(result);
	}
	catch (e)
	{
		var msg = "Error: " + JSON.stringify(e);
		log.info(msg);
	}
 
	return result;
}
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.

emreedemir avatar image emreedemir commented ·

Do you find any way to solve this problem ?

0 Likes 0 ·
Enrico Paracchini avatar image
Enrico Paracchini answered

have you a News about this method?

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.