Add new users to the workspace
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 FastReport Corporate Server.
This article will skip over additional information on authentication and authorization.
C# code editor or text editor, e.g., Visual Studio Code.
Active FastReport Corporate Server subscription that has 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(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 (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, System.Threading.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
userId
ID to the workspace with thesubscriptionId
ID.To retrieve the list of workspace users, use the following method GetUsersAsync(String, Nullable<Int32>, Nullable<Int32>, System.Threading.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
subscriptionId
ID.To remove a user from the workspace, use the following method RemoveUserAsync(String, String, System.Threading.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
userId
ID from the workspace with thesubscriptionId
ID.