Table of Contents

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:

  1. Know how to use API key in Service solutions.

    This article will skip over additional information on authentication and authorization.

  2. .NET SDK.

  3. C# code editor or text editor, e.g., Visual Studio Code.

  4. 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.

  5. 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

  1. 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.

  2. 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 groupName name for the workspace with the subscriptionId ID, as a result the function will return the ID of the created group.

  3. 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 userId ID to the group with groupId ID.

  4. 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.

What next?