Working with groups
This article walks you through 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 features:
Knowledge of using API key in FastReport Cloud.
This article will skip additional information on authentication and authorization.
A C# code editor or a text editor such as Visual Studio Code.
Active FastReport Cloud subscription, which has two user slots.
Access to the Internet.
Note! This guide assumes that you already know how to develop your application in the C# programming language.
Note! The paragraphs above describe the recommended tools.
Comment
Note! It is only possible to add a user to a group if the user exists in the workspace.
Note! It is only possible to add a user to a group by its identifier.
Instruction
To create a new group, you need a workspace identifier and a name for the new group.
To get the workspace identifier, use the method GetSubscriptionsAsync(Nullable<Int32>, Nullable<Int32>, System.Threading.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 identifier.
The workspace and the subscription identifiers are the same because one subscription is associated with each workspace.
To create a new group, use the method CreateGroupAsync(CreateGroupVM, System.Threading.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 named
groupName
for the workspace with the subscriptionId identifier, as aresult
, the function will return the identifier of the created group.To add a new user to the group, use the method AddUserToGroupAsync(String, String, System.Threading.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 the user with the
userId
identifier to the group with thegroupId
identifier.To get a list of users in the group, use the method GetUsersInGroupAsync(String, Nullable<Int32>, Nullable<Int32>, System.Threading.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
identifier.