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

 

*Suggested article related to Access Group Creation

http://kb.supremainc.com/knowledge/doku.php?id=en:how_to_make_access_groups

 

Through this article, you can learn how to call an API function to create users to your BioStar 2 server. There were some demands that they wanted to add the users to access groups while creating them via API call. This article will explain how to create users and add them to access groups at the same time by one API call.

 

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 

 

[POST]: /users

[Parameters]

Group

Name

Sub-group

Type

*M/O

Explanation

Value

User

name

 

string

M

User Name

 

 

Email

 

string

O

Email

aaa@suprema.co.kr

 

Photo

 

string

O

User Photo

 

 

Phone

 

string

O

Phone

 

 

User_id

 

string

M

User ID

 

 

User_group_id

id

Integer

M

User Group ID

 

 

Disabled

 

Boolean

M

User Status

Ex) false

 

Start_datetime

 

string

M

Start Datetime

2001-01-01T00:00:00.00Z

 

Expiry_datetime

 

string

M

Expiry Datetime

2030-12-31T23:59:00.00Z

 

Permission

Id

string

O

Permission ID

Permission ID(Get_/api/permissions)

1(Administrator)

2(User Operator)

3(Monitoring Operator)

..(CustomId)

253(Video)

254(TA)

255(User)

100000(Visitor)

 

 

Name

string

O

Test

 

 

 

Description

string

O

Description

 

 

 

Operator – name

string

O

User Name

 

 

 

Operator[] – owner_id

string

O

Permission ID

Permission ID(Get_/api/permissions)

1(Administrator)

2(User Operator)

3(Monitoring Operator)

..(CustomId)

253(Video)(Get_/api/permissions)

1(Administrator)

2(User Operator)

3(Monitoring Operator)

..(CustomId)

253(Video)

254(TA)

255(User)

100000(Visitor)

254(TA)

255(User)

100000(Visitor)

 

 

Operator[] – user_id

string

O

User ID

 

 

Access_groups

Name

string

O

Access Group Name

Already Existed

 

 

Id

Integer

O

Access Group ID

Already Existed

 

Password

 

string

O

Password

 

 

Pin

 

string

O

PIN

 

 

Login_id

 

string

O

Login ID

 

 

User_ip

 

string

O

User IP

 

 

Fingerprint_templates[]

Template0

string

O

Fingerprint binary data

Encoded Base64 String

 

 

Template1

string

O

Fingerprint binary data

Encoded Base64 String

 

 

Finger_mask

Boolean

O

Finger Mask

 

 

 

isNew

boolean

O

New Fingerprint

 

 

Credentials

Faces[] – raw_image

string

O

Face Image Data

 

 

 

Faces[] – templates – template

string

O

Face Credential Data – Face Binary Data

 

 

 

Faces[] – Flag

string

O

Face Flag

 

 

 

Faces[] – useProfile

Boolean

O

Face data use profile

 

 

 

Faces[] – Index

Integer

O

Face Index

 

 

Cards[]

Card_type – id

string

O

Card Type ID

(0:CSN, 1:WIEGAND, 2:SECURE, 3:ACCESS, 4:CSN_MOBILE, 5:WIEGAND_MOBILE, 6:QR/Barcode, 7:BioStar 2 QR)

 

 

Card_type – name

string

O

Card Type Name

 

 

 

Card_type – type

string

O

Card Type

(1:CSN, 2:SECURE, 3:ACCESS, 10:CSN_WIEGAND, 4:CSN_MOBILE, 5:WIEGAND_MOBILE, 6:QR/Barcode, 7:BioStar 2 QR)

 

 

Card_type – mode

string

O

Card Mode

(C:CSN, S:SECURE, A:ACCESS, M:CSN_MOBILE)

 

 

Card_id

string

O

Card ID

 

 

 

Display_card-id

string

O

Display Card ID

 

 

 

Id

string

O

ID

 

 

 

cardId

string

O

Wiegand Card Id

(Use Wiegand)

 

 

Wiegand_format_id – id

string

O

Wiegand Format Id

 

 

 

Wiegand_format__name

string

O

Wiegand Format Name

(Use Wiegand)

* M – Mandatory, O - Optional

 

Part 2. Request Body & Response Model

[Input Example with minimum values]

{

    "User": {

        "name": "AGTEST",

        "user_id": "99999",

        "user_group_id": {

            "id": 1,

            "name": "All Users"

        },

        "disabled": "false",

        "start_datetime": "2001-01-01T00:00:00.00Z",

        "expiry_datetime": "2030-12-31T23:59:00.00Z",

        "access_groups": [{

            "name": "TTTEST",

            "id": 15

        }

        ],

        "login_id": "api2",

        "password": "Peter3820@"

    }

}

 

[Response: Fail]

{

  "Response": {

    "code": "202",

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

    "message": "User who has same id already exists"

  }

}

[Response: Successful]

{

  "UserCollection": {

    "total": "1",

    "rows": [

      {

        "user_id": "99999",

        "name": " AGTEST "

      }

    ]

  },

  "Response": {

    "code": "0",

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

    "message": "Success"

  }

}

 

Part 3. Console Create User with Access Group Example

 

[Create

 Users Method Source Code] 

static async void CreateUserTask()  

        {

            if (sessionID == null)

            {

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

                return;

            }

            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("https://127.0.0.1"), new Cookie("bs-session-id", sessionID));

 

            string resourceAddress = "https://127.0.0.1/api/users";

 

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            Console.WriteLine("Enter USER NAME: ");

            string UserName = Console.ReadLine();

            Console.WriteLine("Enter USER ID: ");

            string UserID = Console.ReadLine();

            Console.WriteLine("Enter USER LOGIN ID: ");

            string User_login_id = Console.ReadLine();

            Console.WriteLine("Enter USER LOGIN PASSWORD: ");

            string User_login_pw = Console.ReadLine();

 

            string payload2 = "{ \"User\": ";

            payload2 = payload2 + "{\"name\": \"" + UserName + "\", ";

            payload2 = payload2 + "\"user_id\": \"" + UserID + "\",";

            payload2 = payload2 + "\"user_group_id\": { \"id\": 1, \"name\": \"All Users\" },\"disabled\": \"false\",\"start_datetime\": \"2001-01-01T00:00:00.00Z\", \"expiry_datetime\": \"2030-12-31T23:59:00.00Z\", ";

            payload2 = payload2 + "\"access_groups\"": [{\"name\": \"TTTEST\",\"id\": 15 }],";

            payload2 = payload2 + "\"login_id\": \""+ User_login_id +"\", ";

            payload2 = payload2 + "\"password\": \"" + User_login_pw  + "\"}}";

            Console.WriteLine(payload2);

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

            

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

 

 

            if (httpResponse.IsSuccessStatusCode == true)

            {

                Console.WriteLine("User has been created");

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

                   Console.WriteLine(httpResponseBody);

            }

            else

            {

                Console.WriteLine("User Creation Failed");

                   Console.WriteLine(httpResponse.ToString());

            }

        }

 

[After Creating User Successfully] 

 

 

 

Part 4. Create User with Access Group 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] 

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

자동 생성된 설명