Introduction

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 cover the most basic usage of the BioStar 2 New Local API by C# console application. 

 

This is just a sample application made for those who might need to use the BioStar 2 New Local API. It is a Visual C# console application.

 

Features

This article will cover the functions below:

  1. Login
  2. Search Users
  3. Create Users
  4. Create Users with Access Group
  5. Retrieve Log Data
  6. Retrieve Log Data with order by

 

Through this article, you can learn how to call an API function to search for the users that are registered to your BioStar 2 server. In most cases, [GET] call doesn’t include any parameters since it is simply retrieving the information from the server. [GET] /users call which retrieves the user information of your server also doesn’t have any parameters(input).

 

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 

 

[GET]: /users

[Parameters] 

Name

Type

*M/O

Explanation

Value

 

 

 

 

 

   * M – Mandatory, O – Optional

 

Part 2. Request Body & Response Model

[Example Value/Parameters Model]

 

 

[Response Model]

{

UserCollection  Res____UserCollection____6___C{

total       string

example: 8

@desc: User Total

 

rows      [{

user_id string

example: 2

@desc: User Id

 

name    string

example: 11

@desc: User Name

 

gender string

example: 0

@desc: User Gender

 

photo_exists     boolean

example: false

@desc: Use User Photo Exists

 

pin_exists           boolean

example: false

@desc: Use User Pin Exists

 

password_exists              boolean

example: false

@desc: Use User Password Exists

 

updated_count string

example: 1

@desc: User Updated Count

 

last_modified    string

example: 25

@desc: User Last Modified

 

start_datetime string

example: 2001-01-01T00:00:00.00Z

@desc: User Start Datetime

 

expiry_datetime              string

example: 2030-12-31T23:59:00.00Z

@desc: User Expiry Datetime

 

security_level    string

example: 0

@desc: User Security Level

 

display_duration              string

example: 0

@desc: User Display Duration

 

display_count    string

example: 0

@desc: User Display Count

 

inherited             boolean

example: false

@desc: Use User Inherited

 

user_group_id  {

id            string

example: 1010

@desc: User Group Id

 

name    string

example: 123

@desc: User Group Id Name

 

}

disabled               boolean

example: false

@desc: Use User Disabled

 

expired boolean

example: false

@desc: Use User Expired

 

fingerprint_template_count       string

example: 1

@desc: User Fingerprint Template Count

 

face_count         string

example: 0

@desc: User Face Count

 

card_count         string

example: 0

@desc: User Card Count

 

access_groups  [{

id            string

example: 3

@desc: Access Group Id

 

name    string

example: as

@desc: Access Group Name

 

}]

access_groups_in_user_group   [{

id            string

example: 3

@desc: Access Groups In User Group Id

 

name    string

example: as

@desc: Access Groups In User Group Name

 

}]

}]

}

Response            Res____Response___C{

code      string

example: 0

desc : Response.code reference: C:\Program Files\BioStar 2(x64)\nginx\html\resources\messages_en.properties(ACB_ERROR_CODE.XXXXX)

 

link         string

example: https://support.supremainc.com/en/support/home

desc: Link URL

 

message              string

example: Success

desc: Message

 

}

httpResponseStatus       Res____httpResponseStatus___Cinteger

example: 200

desc: HTTP Status Code

 

}

[Response: Fail]

{

    "Response": {

        "code": "10",

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

        "message": "Login required."

    }

}

[Response: Successful]

{

    "UserCollection": {

        "total": "8",

        "rows": [

            {

                "user_id": "1",

                "name": "Administrator",

                "gender": "0",

                "email": "peterk@suprema.co.kr",…

   "Response": {

        "code": "0",

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

        "message": "Success"

    }

}

 

Part 3. Console Search User Example

 

[Search Users Method Source Code] 

static async void ListUsers()

        {

            if (sessionID == null)

            {

                Console.WriteLine("You must log in first!");

                return;

            }

 

            CookieContainer cookieContainer = new CookieContainer();

 

            HttpClientHandler handler = new HttpClientHandler();

            handler.CookieContainer = cookieContainer;

 

            HttpClient client = new HttpClient(handler);

 

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

            cookieContainer.Add(new Uri("https://127.0.0.1"), new Cookie("bs-session-id", sessionID));

            HttpResponseMessage httpResponse = client.GetAsync("https://127.0.0.1/api/users").Result;

 

 

            if (httpResponse.IsSuccessStatusCode == true)

            {

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

                //Console.WriteLine(httpResponseBody);

                dynamic obj = JsonConvert.DeserializeObject(httpResponseBody);

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

                int UserTotal = obj.UserCollection.total;

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

                {

                       Console.WriteLine(obj.UserCollection.rows[i].user_id + "        " + obj.UserCollection.rows[i].name);

                }

            }

            else

            {

                Console.WriteLine("Listing Users Failed");

                   Console.WriteLine(httpResponse.ToString());

            }

        }

 

 

[After Search User Successfully] 

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

자동 생성된 설명

 

*It only outputs the User ID and User Name since the source code only outputs those 2 values of each user.

 

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

 

[Response Example: body] 

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

자동 생성된 설명