This article will guide you through viewing user groups in BioStar 2 server via BioStar 2 API.  


You can find a more detailed introduction to BioStar 2 New Local API in this article : [BioStar 2 API] How To Use BioStar 2 New Local API 

 

In this article, you can learn how to call an API function to view user groups in your BioStar 2 server. 

 

This article also includes a sample code of a C# program that incorporates the API, and also an example of API call made via Postman, a program used for building & testing RESTful API calls.

 


There are two different APIs you can use to achieve this and this article will go through each one in details. * 


1.       [GET]     /user_groups

You can also find information regarding this API in the following link : List User Groups API Documentation


Postman Request Example 


Postman Response Body Example: 

As you can see below, it shows details for two user groups that are on my BioStar 2 server. 



This is another way of searching user groups. 


2.       [POST]     /v2/user_groups/search


You can also find information regarding this API in the following link : List User Groups API Documentation V2


[Parameters]

ParametersTypeRequiredDescription
user_group_id_listArrayN
Specify User Group ids which will be viewed. 
Use comma (,) as separator.


Postman Request Example: 

If you want to retrieve all user groups, put {} for request body. 


Postman Response Body Example: 

As you can see below, it only retrieved the user group details for user group with id "1". 


C# Sample Code of API incorporated program  

 

[Search User Groups Method Source Code] 

static async void SearchUserGroup()

        {

            Console.WriteLine("*****SearchUserGroup Task Started*****");

            CookieContainer cookieContainer = new CookieContainer();

 

            HttpClientHandler handler = new HttpClientHandler();

            handler.CookieContainer = cookieContainer;

 

            HttpClient httpClient = new HttpClient(handler);

 

            HttpClient client = new HttpClient(handler);

            httpClient.DefaultRequestHeaders.Add("bs-session-id", sessionID);

            cookieContainer.Add(new Uri(BioStarIP), new Cookie("bs-session-id", sessionID));

            string resourceAddress = BioStarIP + "/api/v2/user_groups/search";

 

            JavaScriptSerializer serializer = new JavaScriptSerializer();

 

            string payload = "{}";

            Console.WriteLine(payload);

            StringContent sc = new StringContent(payload, Encoding.UTF8, "application/json");

            HttpResponseMessage httpResponse = httpClient.PostAsync(resourceAddress, sc).Result;

 

            if (httpResponse.IsSuccessStatusCode == true)

            {

                string httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                   Console.WriteLine(httpResponseBody);

                dynamic obj = JsonConvert.DeserializeObject(httpResponseBody);

                Console.WriteLine("**** USER GROUP LIST: ****");

                int UserTotal = obj.UserGroupCollection.total;

                for (int i = 0; i < UserTotal; i++)

                {

                       Console.WriteLine(obj.UserGroupCollection.rows[i].id + "        " + obj.UserGroupCollection.rows[i].name);

                }

            }

            else

            {

                Console.WriteLine("Search User Group Failed.");

                   Console.WriteLine(httpResponse.ToString());

            }

        }

 

After Search User Groups Successfully using the program above: 

텍스트이(가) 표시된 사진

자동 생성된 설명