Add new users to a subscription
This article describes how to add a new user to the subscription, get a list of the subscription members and remove the user from the subscription.
Getting started
You will need the following tools and features:
Knowledge on how to use API key in FastReport Corporate Server.
This article does not include the information about authentication and authorization.
A C# code editor or a text editor like Visual Studio Code.
Active subscription for FastReport.Cloud with two slots for the user.
Internet access.
Please, note: This tutorial assumes that you already know how to develop your application with the C# programming language.
Please, note: The descriptions above are provided for the recommended tools.
Remark
Please, note: You can add a user to a subscription only by the user's identifier.
Instructions
To add a new user to a subscription, a subscription identifier is required.
To get the subscription identifier, use the <xref:FastReport.Cloud.ISubscriptionsClient.GetSubscriptionsAsync(System.Nullable{System.Int32},System.Nullable{System.Int32})> method.
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 subscriptions from the user's list of subscriptions, selects the first subscription, and returns its identifier.
To add a new user, use the <xref:FastReport.Cloud.ISubscriptionUsersClient.AddUserAsync(System.String,System.String)> method.
public async Task AddUser(HttpClient httpClient, string subscriptionId, string userId) { ISubscriptionUsersClient subscriptionUsersClient = new SubscriptionUsersClient(httpClient); await subscriptionUsersClient.AddUserAsync(subscriptionId, userId); }
In this example, function adds a user with the identifier userId
to the subscription with the identifier subscriptionId
.
To get a list of subscription users, use the <xref:FastReport.Cloud.ISubscriptionUsersClient.GetUsersAsync(System.String,System.Nullable{System.Int32},System.Nullable{System.Int32})> method.
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 subscription with the identifier
subscriptionId
.To remove a user from a subscription, use the <xref:FastReport.Cloud.ISubscriptionUsersClient.RemoveUserAsync(System.String,System.String)> method.
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 identifier
userId
from the subscription with the identifiersubscriptionId
.