If you’d like to use BioStar 2 New Local API as a RESTful API for your own customization or other purposes, you can simply reference this article. This article will help you to search user groups in your BioStar 2 via using New local API. 

 

This article includes a ‘Search User Group’ part of a sample application made for those who might need to use the BioStar 2 New Local API. It is a Visual C# console application.

 

Make sure you take a good look at the example code of the C# program built for API calls. You can simply copy & paste the source code to use the same function in your own integration. 

 

You can also see how to call the API functions via Postman, which is a program used for RESTful API calls.

 

Part 1. API Call & Parameters 

  1. How to Search for User Groups

 

Method

API

What it does

Parameters

POST

/api/v2/user_groups/search

Search for all the user groups in BioStar 2

 

 

[POST] /api/v2/user_groups/search

[Parameters]

Name

Type

*M/O

Explanation

Parameter Type

 

 

 

 

 

* M – Mandatory, O – Optional

 

Part 2. Request Body & Response Model

 

[Example Value/Parameters Model]

 

 

[Response Model]

{

     "UserGroupCollection": {

       "total": 1,

       "rows": [

         {

           "id": 1,

           "name": "All Users",

           "depth": 0,

           "user_count": 1002

         }

       ]

     },

     "Response": {

       "code": "0"

     },

     "httpResponseStatus": 200

}

 

[Response: Fail]

{

       "Response": {

           "code": "10",

           "link": "https://support.supremainc.com/en/support/home",

           "message": "Login required."

       }

}

 

[Response: Successful]

{

       "UserGroupCollection": {

           "total": 4,

           "rows": [

            {

                "id": 1,

                "name": "All Users",

                "depth": 0,

                "user_count": 4

            },

            {

                "id": 10000281,

                "name": "New Group 44",

                "depth": 1,

                   "user_count": 2,

                "parent_id": {

                    "id": 1

                }

            },

            {

                "id": 10000280,

                "name": "New User Group",

                "depth": 1,

                "user_count": 0,

                "parent_id": {

                    "id": 1

                }

            },

            {

                "id": 10000278,

                "name": "New User Group 1",

                "depth": 1,

                "user_count": 0,

                "parent_id": {

                    "id": 1

                }

            }

           ]

       },

       "Response": {

        "code": "0"

       }

}

 

Part 3. Console Search User Groups Example

 

[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] 

 

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

자동 생성된 설명

 

 

Part 4. Search User Groups via Postman

 

[Request Example: Headers] 

*You must use the ‘be-session-id’ value from the response header of the Login API call to authenticate API use for other API calls.

텍스트, 스크린샷, 모니터, 화면이(가) 표시된 사진

자동 생성된 설명

 

[Request Example] 

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

자동 생성된 설명

*Nothing is required for request body

 

[Response Example: body] 

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

자동 생성된 설명