Manage group roles
Last updated on December 18, 2024
Overview
This article guides you through integrating the AccelByte Gaming Services (AGS) Group service into your game client to enable the following functionalities:
- Retrieving group roles
- Allowing group admins to assign and remove member roles
How-to Guide
Group roles are created in the AGS Admin Portal. For more information, refer to the how-to guide for configuring groups.
Retrieve group roles
To enable your game client to retrieve group roles that exist in your namespace, use this code:
- Unreal Engine V1
- Unity V1
- Unreal Engine V2
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FAccelByteModelsLimitOffsetRequest RequestContent = {};
RequestContent.Limit = 100;
RequestContent.Offset = 0;
ApiClient->Group.GetMemberRoles(RequestContent, THandler<FAccelByteModelsGetMemberRolesListResponse>::CreateLambda([](const FAccelByteModelsGetMemberRolesListResponse& Result)
{
// Do something if GetMemberRoles succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetMemberRoles fails
}));
int limit = 100;
int offset = 0;
AccelByteSDK.GetClientRegistry().GetApi().GetGroup().GetMemberRoles(limit, offset, result =>
{
if (result.IsError)
{
// Do something if GetMemberRoles fails
Debug.Log($"Error GetMemberRoles, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if GetMemberRoles succeeds
});
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FAccelByteModelsLimitOffsetRequest RequestContent = {};
RequestContent.Limit = 100;
RequestContent.Offset = 0;
ApiClient->Group.GetAllMemberRoles(RequestContent, THandler<FAccelByteModelsGetMemberRolesListResponse>::CreateLambda([](const FAccelByteModelsGetMemberRolesListResponse& Result)
{
// Do something if GetAllMemberRoles succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetAllMemberRoles fails
}));
groupRolesService := &group.GroupRolesService{
Client: factory.NewGroupClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
namespace := "mygame"
limit := int64(100)
offset := int64(0)
input := &group_roles.GetMemberRolesListPublicV2Params{
Namespace: namespace,
Limit: &limit,
Offset: &offset,
}
result, err := groupRolesService.GetMemberRolesListPublicV2Short(input)
import accelbyte_py_sdk.api.group as group_service
result, error = group_service.get_member_roles_list_public_v2(
limit=100,
offset=0,
)
if error:
exit(error)
final GroupRoles groupRolesWrapper = new GroupRoles(sdk);
String userId = "YourUserId";
int limit = 100;
int offset = 0;
ModelsGetMemberRolesListResponseV1 response;
try {
response = groupRolesWrapper.getMemberRolesListPublicV2(GetMemberRolesListPublicV2.builder()
.namespace("<namespace>")
.limit(limit)
.offset(offset)
.build());
} catch (Exception e) {
// Do something if an error occurs
return;
}
var response = sdk.Group.GroupRoles.GetMemberRolesListPublicV2Op
.SetOffset(0)
.SetLimit(100)
.Execute(sdk.Namespace);
if (response != null)
{
// Do something when successful
}
Assign group roles
To enable group admins to assign roles to members, use this code:
- Unreal Engine V1
- Unity V1
- Unreal Engine V2
- Unity V2
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString MemberRoleId = "YourMemberRoleId";
FAccelByteModelsUserIdWrapper RequestContent = {};
RequestContent.UserId = "YourUserId";
ApiClient->Group.AssignMemberRole(MemberRoleId, RequestContent, THandler<FAccelByteModelsGetUserGroupInfoResponse>::CreateLambda([](const FAccelByteModelsGetUserGroupInfoResponse& Result)
{
// Do something if AssignMemberRole succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if AssignMemberRole fails
}));
string memberRoleId = "YourMemberRoleId";
string userId = "YourUserId";
AccelByteSDK.GetClientRegistry().GetApi().GetGroup().AssignRoleToMember(memberRoleId, userId, result =>
{
if (result.IsError)
{
// Do something if AssignRoleToMember fails
Debug.Log($"Error AssignRoleToMember, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if AssignRoleToMember succeeds
});
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString MemberRoleId = "YourMemberRoleId";
FString GroupId = "YourGroupId";
FAccelByteModelsUserIdWrapper RequestContent = {};
RequestContent.UserId = "YourUserId";
ApiClient->Group.AssignV2MemberRole(MemberRoleId, GroupId, RequestContent, THandler<FAccelByteModelsGetUserGroupInfoResponse>::CreateLambda([](const FAccelByteModelsGetUserGroupInfoResponse& Result)
{
// Do something if AssignV2MemberRole succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if AssignV2MemberRole fails
}));
string memberRoleId = "YourMemberRoleId";
string userId = "YourUserId";
string groupId = "YourGroupId";
AccelByteSDK.GetClientRegistry().GetApi().GetGroup().AssignRoleToMemberV2(memberRoleId, userId, groupId, result =>
{
if (result.IsError)
{
// Do something if AssignRoleToMemberV2 fails
Debug.Log($"Error AssignRoleToMemberV2, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if AssignRoleToMemberV2 succeeds
});
groupRolesService := &group.GroupRolesService{
Client: factory.NewGroupClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
userId := "myuserid"
body := groupclientmodels.ModelsAssignRoleToMemberRequestV1 {
UserID: &userId,
}
groupId := "mygroupid"
memberRoleId := "mymemberroleid"
namespace := "mygame"
input := &group_roles.UpdateMemberRolePublicV2Params{
Body: &body,
GroupID: groupId,
MemberRoleID: memberRoleId,
Namespace: namespace,
}
result, err := groupRolesService.UpdateMemberRolePublicV2Short(input)
import accelbyte_py_sdk.api.group as group_service
import accelbyte_py_sdk.api.group.models as group_models
result, error = group_service.update_member_role_public_v2(
body=group_models.ModelsAssignRoleToMemberRequestV1()
.with_user_id("********************************"),
group_id="GroupId",
member_role_id="YourMemberRoleId",
)
if error:
exit(error)
final GroupRoles groupRolesWrapper = new GroupRoles(sdk);
String memberRoleId = "YourMemberRoleId";
String userId = "YourUserId";
String groupId = "YourGroupId";
ModelsGetUserGroupInformationResponseV1 response;
try {
ModelsAssignRoleToMemberRequestV1 body = ModelsAssignRoleToMemberRequestV1.builder().
userId(userId).build();
response = groupRolesWrapper.updateMemberRolePublicV2(UpdateMemberRolePublicV2.builder()
.namespace("<namespace>")
.memberRoleId(memberRoleId)
.body(body)
.build());
} catch (Exception e) {
// Do something if an error occurs
return;
}
string memberRoleId = "YourMemberRoleId";
string userId = "<user-id>";
string groupId = "<group-id>";
var response = sdk.Group.GroupRoles.UpdateMemberRolePublicV2Op
.Execute(new ModelsAssignRoleToMemberRequestV1()
{
UserId = userId
}, groupId, memberRoleId, sdk.Namespace);
if (response != null)
{
// Do something when successful
}
Remove a member's role
To enable group admins to remove a member's role, use this code:
- Unreal Engine V1
- Unity V1
- Unreal Engine V2
- Unity V2
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString MemberRoleId = "YourMemberRoleId";
FAccelByteModelsUserIdWrapper RequestContent = {};
RequestContent.UserId = "YourUserId";
ApiClient->Group.DeleteMemberRole(MemberRoleId, RequestContent, FVoidHandler::CreateLambda([]()
{
// Do something if DeleteMemberRole succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if DeleteMemberRole fails
}));
string memberRoleId = "YourMemberRoleId";
string userId = "YourUserId";
AccelByteSDK.GetClientRegistry().GetApi().GetGroup().RemoveRoleFromMember(memberRoleId, userId, result =>
{
if (result.IsError)
{
// Do something if RemoveRoleFromMember fails
Debug.Log($"Error RemoveRoleFromMember, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if RemoveRoleFromMember succeeds
});
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString MemberRoleId = "YourMemberRoleId";
FString GroupId = "YourGroupId";
FAccelByteModelsUserIdWrapper RequestContent = {};
RequestContent.UserId = "YourUserId";
ApiClient->Group.DeleteV2MemberRole(MemberRoleId, GroupId, RequestContent, FVoidHandler::CreateLambda([]()
{
// Do something if DeleteV2MemberRole succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if DeleteV2MemberRole fails
}));
string memberRoleId = "YourMemberRoleId";
string userId = "YourUserId";
string groupId = "YourGroupId";
AccelByteSDK.GetClientRegistry().GetApi().GetGroup().RemoveRoleFromMemberV2(memberRoleId, userId, groupId, result =>
{
if (result.IsError)
{
// Do something if RemoveRoleFromMemberV2 fails
Debug.Log($"Error RemoveRoleFromMemberV2, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if RemoveRoleFromMemberV2 succeeds
});
groupRolesService := &group.GroupRolesService{
Client: factory.NewGroupClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
userId := "myuserid"
body := groupclientmodels.ModelsRemoveRoleFromMemberRequestV1 {
UserID: &userId,
}
groupId := "mygroupid"
memberRoleId := "mymemberroleid"
namespace := "mygame"
input := &group_roles.DeleteMemberRolePublicV2Params{
Body: &body,
GroupID: groupId,
MemberRoleID: memberRoleId,
Namespace: namespace,
}
err := groupRolesService.DeleteMemberRolePublicV2Short(input)
import accelbyte_py_sdk.api.group as group_service
import accelbyte_py_sdk.api.group.models as group_models
result, error = group_service.delete_member_role_public_v2(
body=group_models.ModelsRemoveRoleFromMemberRequestV1()
.with_user_id("********************************"),
group_id="GroupId",
member_role_id="YourMemberRoleId",
)
if error:
exit(error)
final GroupRoles groupRolesWrapper = new GroupRoles(sdk);
String memberRoleId = "YourMemberRoleId";
String userId = "YourUserId";
String groupId = "YourGroupId";
ModelsGetUserGroupInformationResponseV1 response;
try {
ModelsRemoveRoleFromMemberRequestV1 body = ModelsRemoveRoleFromMemberRequestV1.builder().
userId(userId).build();
groupRolesWrapper.deleteMemberRolePublicV2(DeleteMemberRolePublicV2.builder()
.namespace("<namespace>")
.memberRoleId(memberRoleId)
.body(body)
.build());
} catch (Exception e) {
// Do something if an error occurs
return;
}
string memberRoleId = "YourMemberRoleId";
string userId = "<user-id>";
string groupId = "<group-id>";
sdk.Group.GroupRoles.DeleteMemberRolePublicV2Op
.Execute(new ModelsRemoveRoleFromMemberRequestV1()
{
UserId = userId
}, groupId, memberRoleId, sdk.Namespace);