Add new users to the workspace
Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher
This article covers the process of adding a new user to a subscription, retrieving the list of users, and removing a user from it.
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! It is only possible to add a user to a workspace by user ID.
Instruction
To add a new user to a workspace, a workspace (subscription) ID is required.
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 (subscriptions) from the user's list of workspaces, selects the first workspace, and returns its ID.
A workspace always is associated with the one subscription, so they have the same ID.
To add a new user, use the following method AddUserAsync(string, string, CancellationToken).
public async Task AddUser(HttpClient httpClient, string subscriptionId, string userId) { ISubscriptionUsersClient subscriptionUsersClient = new SubscriptionUsersClient(httpClient); await subscriptionUsersClient.AddUserAsync(subscriptionId, userId); }In this example, the function adds the user with the
userIdID to the workspace with thesubscriptionIdID.To retrieve the list of workspace users, use the following method GetUsersAsync(string, int?, int?, CancellationToken).
public async Task<IEnumerable<string>> GetUsers(HttpClient httpClient, string subscriptionId) { ISubscriptionUsersClient subscriptionUsersClient = new SubscriptionUsersClient(httpClient); SubscriptionUsersVM users = await subscriptionUsersClient.GetUsersAsync(subscriptionId, 0, 10); return users.Users.Select(m => m.UserId); }In this example, the function requests the first 10 users from a workspace with the
subscriptionIdID.To remove a user from the workspace, use the following method RemoveUserAsync(string, string, CancellationToken).
public async Task RemoveUser(HttpClient httpClient, string subscriptionId, string userId) { ISubscriptionUsersClient subscriptionUsersClient = new SubscriptionUsersClient(httpClient); await subscriptionUsersClient.RemoveUserAsync(subscriptionId, userId); }In this method, the function removes the user with the
userIdID from the workspace with thesubscriptionIdID.