Work with groups
Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher
This article covers the process of creating a new group, adding a user to the group, and getting a list of the group's users.
Getting started
You will need the following tools and facilities:
Know how to use API key in Service solutions.
This article will skip over additional information on authentication and authorization.
C# code editor or text editor, e.g., Visual Studio Code.
Active subscription to one of the following products: FastReport Cloud, FastReport Corporate Server, or FastReport Publisher. The subscription must have at least two user slots.
Internet access.
Important! These guides assume that you already know how to develop your application in the C# programming language.
Note. The items above describe recommended tools.
Annotation
Important! Adding a user to a group is only possible if the user exists in the workspace.
Important! It is possible to add a user to a group only by their ID.
Instruction
To create a new group, you need a workspace ID and the name of the new group.
To retrieve the workspace ID, use the following method GetSubscriptionsAsync(int?, int?, CancellationToken).
public async Task<string> GetSubscriptionId(HttpClient httpClient) { ISubscriptionsClient subscriptionsClient = new SubscriptionsClient(httpClient); SubscriptionsVM subscriptions = await subscriptionsClient.GetSubscriptionsAsync(0, 10); SubscriptionVM subscription = subscriptions.Subscriptions.First(); return subscription.Id; }In this example, the function requests the first 10 workspaces from the user's list of workspaces, selects the first workspace, and returns its ID.
The ID of a workspace and a subscription are the same because one subscription is associated with each workspace.
To create a new group, use the following method CreateGroupAsync(CreateGroupVM, CancellationToken).
public async Task<string> CreateGroup(HttpClient httpClient, string subscriptionId, string groupName) { IGroupsClient groupsClient = new GroupsClient(httpClient); CreateGroupVM viewModel = new CreateGroupVM() { Name = groupName, SubscriptionId = subscriptionId }; GroupVM group = await groupsClient.CreateGroupAsync(viewModel); return group.Id; }In this example, the function creates a new group with the
groupNamename for the workspace with thesubscriptionIdID, as a result the function will return the ID of the created group.To add a new user to the group, use the following method AddUserToGroupAsync(string, string, CancellationToken).
public async Task AddUser(HttpClient httpClient, string groupId, string userId) { IGroupUsersClient groupUsersClient = new GroupUsersClient(httpClient); await groupUsersClient.AddUserToGroupAsync(groupId, userId); }In this example, the function adds a user with the
userIdID to the group withgroupIdID.To retrieve the list of users in the group, use the following method GetUsersInGroupAsync(string, int?, int?, CancellationToken).
public async Task<IEnumerable<string>> GetUsers(HttpClient httpClient, string groupId) { IGroupUsersClient groupUsersClient = new GroupUsersClient(httpClient); GroupUsersVM users = await groupUsersClient.GetUsersInGroupAsync(groupId, 0, 10); return users.Users.Select(m => m.UserId); }In this example, the function requests the first 10 users from the group with the
groupId.