This article will guide you through searching for users 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 the users that are registered to 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]: /users
You can also find information regarding this API in the following link : List All Users API Documentation
[Query Parameters]
Name | Type | *M/O | Explanation |
limit | int | O | Limit response record(s) by the amount specified on this parameter. Default value : 0 (or don't add parameter) to show all. |
group_id | int | O | Filter response record(s) according to the group_id specified no this parameter. Default value: 1 (or don't put parameter) to show all. |
offset | int | O | Shift response record(s) by the amount specified on this parameter. Default value : 0 |
order_by | boolean | O | Order the response record(s) by the User parameter such as user_id or name. False for ascending, True for descending. Default value : user_id:false |
last_modified | int | O | Show response record(s) with User last_modified value which is equal or greater than this parameter value. Default value : 0 |
* M – Mandatory, O – Optional
Part 2. Request Body & Response Model
[No Request Body Example as this API does not have any Body Parameters.]
[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 Example: Fail]
{ "Response": { "code": "10", "link": "https://support.supremainc.com/en/support/home", "message": "Login required." } } |
[Response Example: 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
This is a sample of Visual C# console application made for those who might need some guide for integrating the BioStar 2 New Local API.
You can simply copy & paste the source code to use the same function in your own integration.
[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]