This article will guide you through searching access levels 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 search for access levels that 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. 

 

 

Part 1. API Call & Parameters 

 

[GET]         /api/access_levels

[Query Parameters]

ParameterTypeRequiredDescription
limitNumberN
Limit response record(s) by the amount specified on this parameter. 0 for show all.
offsetNumberNShift response record(s) by the amount specified on this parameter. default value = 0 
order_byString
N
Order the response record(s)
query
stringNnumber of results (from the last value) 

 


Part 2. Request Body & Response Model

  

[Response Model]

{

     "AccessLevelCollection": {

       "total": "0"

     },

     "Response": {

       "code": "1003",

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

       "message": "Success"

     },

     "httpResponseStatus": 200

}

 

[Response: Fail]

{

       "Response": {

           "code": "10",

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

           "message": "Login required."

       }

}

 

[Response: Successful]

{

       "AccessLevelCollection": {

           "total": "7",

           "rows": [

            {

                "id": "1",

                "name": "All",

                "description": "",

                   "access_level_items": [

                    {

                        "id": "14",

                        "doors": [

                            {

                                   "id": "32",

                                   "name": "Test Door"

                            }

                        ],

                           "schedule_id": {

                            "id": "1",

                            "name": "Always"

                        }

                    }

                ]

            },

            {

                "id": "3",

                "name": "lvl_test1",

                "description": ""

            },

            {

                "id": "15",

                "name": "0819 Access Level",

                "description": "Created on 2021-08-19"

            },

            {

                "id": "16",

                "name": "New Access Level",

                "description": "New Access Level Desc"

            },

            {

                "id": "17",

                "name": "Console Access Level",

                "description": "Console made this Access Level",

                   "access_level_items": [

                    {

                        "id": "12",

                           "schedule_id": {

                            "id": "1",

                            "name": "Always"

                        }

                       }

                ]

            },

            {

                "id": "18",

                "name": "as",

                "description": "string",

                   "access_level_items": [

                    {

                        "id": "13",

                           "schedule_id": {

                            "id": "1",

                            "name": "Always"

                        }

                    }

                ]

            },

            {

                "id": "20",

                   "name": "as2",

                "description": "Console made this Access Level"

            }

           ]

       },

       "Response": {

           "code": "0",

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

           "message": "Success"

       }

}

 


Part 3. Console Search Access Levels Example

 

[Search Access Levels Method C# Source Code Example] 

static async void SearchAccessLevels()

        {

            Console.WriteLine("*****SearchAccessLevels 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/access_levels";

 

            JavaScriptSerializer serializer = new JavaScriptSerializer();

 

            HttpResponseMessage httpResponse = httpClient.GetAsync(resourceAddress).Result;

 

            if (httpResponse.IsSuccessStatusCode == true)

            {

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

                   Console.WriteLine(httpResponseBody);

                dynamic obj = JsonConvert.DeserializeObject(httpResponseBody);

                Console.WriteLine("**** ACCESS LEVEL LIST: ****");

                int UserTotal = obj.AccessLevelCollection.total;

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

                {

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

                }

            }

            else

            {

                Console.WriteLine("Search Access Level Failed.");

                   Console.WriteLine(httpResponse.ToString());

            }

        }

 

[After running the above code] 

 

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

자동 생성된 설명

 

 

Part 4. Search Access Levels via Postman

 

[Request Example: Headers] 

* Please note that you must obtain the ‘be-session-id’ value from the response header of the Login API call and input it in the request header of other APIs in order to authenticate other API calls. 

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

자동 생성된 설명

 

[Request Example]

*Nothing is required for request body


[Response Example: body] 

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

자동 생성된 설명