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 Access Levels in your BioStar 2 via using New local API. 

 

This article includes a ‘Search Access Levels’ 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.

 

*Before we start 

Before we enter Access Levels, you must know about Access Groups. Access Group is a higher concept than the Access Level. Access Group is consisted of User Groups & Access Levels.

 

 

Part 1. API Call & Parameters 


 

  1. How to Search for Access Levels

 

Method

API

What it does

Parameters

GET

/api/access_levels

Search for all the Access Levels in BioStar 2

*Check below

 

[GET] /api/access_levels

[Parameters]

Name

Type

*M/O

Explanation

Parameter Type

Limit

String

O

Number of results

 

Offset

String

O

Result offset

 

Order_by

String

O

Order by

 

Query

String

O

Number of results (from the last value)

 

Total

String

O

 

 

* M – Mandatory, O – Optional

 

Part 2. Request Body & Response Model

 

[Example Value/Parameters 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 Source Code] 

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 Search Access Levels Successfully] 

 

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

자동 생성된 설명

 

 

Part 4. Search Access Levels 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] 

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

자동 생성된 설명