This article will guide you through logging in to 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 login to your BioStar 2 server. 

The Login API is an important step in authorizing the user to be able to use other BioStar 2 APIs. 

In order to authorize and use other APIs, please pay attention to how to use ‘bs-session-id’ after you make a successful login call.  

 

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 

 

[POST]: /login

You can also find information regarding the Login API in the following document : Login API Documentation


[Body Parameters] 

Group

Name

Type

*M/O

Explanation

Value

User

login_id

string

M

Login ID

 

 

password

string

M

Password

 

   * M – Mandatory, O – Optional

 

Part 2. Request Body & Response Model

[Example Value/Parameters Model]

{

  "User": {

    "login_id": "admin",

    "password": "qwer1234"

  }

}

 

[Response Model]

{

User      Res____User____272{

user_id string

example: 1

desc: User ID

 

name    string

example: Administrator

desc: Name

 

gender string

example: 1

@desc: User Gender

 

birthday   string

example: 1977-10-08T04:00:00.00Z

@desc: User Birthday

 

photo_exists     boolean

example: false

desc: Check Photo

 

pin_exists           boolean

example: false

desc: Check PIN

 

login_id string

example: admin

desc: Login ID

 

password_exists              boolean

example: true

desc: Check Password

 

updated_count   string

example: 0

desc: Update Count

 

last_modified    string

example: 0

desc: Last Modify

 

start_datetime   string

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

desc: Start DateTime

 

expiry_datetime      string

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

desc: Expiry DateTime

 

security_level    string

example: 0

desc: Security Level

~

}

{

Response            Res____Response{

code      string

example: 1003

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____httpResponseStatusinteger

example: 200

desc: HTTP Status Code

}

 


[Response Example: Fail]

{

    "Response": {

        "code": "101",

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

        "message": "Failed to login for invalid username or password"

    }

}


[Response Example: Successful]

{

    "User": {

        "user_id": "1",

        "name": "Administrator",

        "gender": "0",

        "photo_exists": "false",

        "pin_exists": "false",

        "login_id": "admin",

        "password_exists": "true",

        "updated_count": "37",

        "last_modified": "63",

        "idx_last_modified": "24",

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

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

        "security_level": "0",

~    },

    "Response": {

        "code": "0",

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

        "message": "Success"

    }

}

 

Part 3. Console Login 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.

 

[Login Method Source Code] 

static async void LoginTask()

        {

            string resourceAddress = "https://127.0.0.1:443/api/login"; //Enter your BioStar 2 address & the API call you’d like to perform(login in this case)

 

            HttpClient httpClient = new HttpClient();

            

            JavaScriptSerializer serializer = new JavaScriptSerializer();

                 

            Dictionary<string, string> dicLoginUser = new Dictionary<string, string>();

           

            dicLoginUser.Add("login_id", "admin"); // Enter BioStar 2 Admin Login ID

            dicLoginUser.Add("password", "adminPassword"); // Enter your password of BioStar 2 Admin

            Dictionary<string, object> dicLogin = new Dictionary<string, object>();

            dicLogin.Add("User", dicLoginUser);  // Save your ID and PW to a parameter named “User” and add it to dicLogin

 

            string jsonLoginUser = serializer.Serialize(dicLogin);

            

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

 

            // To load HTTPS Certificate

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            

            //This is an example line to allow the certificate check is secure. You can have your own line for better secure of your application.

            //Please search stackoverflow for the error description - The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

            //A common reason you may receive the error above Could not establish trust relationship for the SSL/TLS secure channel is because the SSL certificate isn't trusted. 

           //Below code ignore the untrusted cert errors. 

            System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

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

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

 

            if (httpResponse.IsSuccessStatusCode == true)

            {

                   Console.WriteLine(httpResponse.ToString());

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

                //Console.WriteLine(httpResponseBody);

                Console.WriteLine("Login successful...");

 

 

                MemoryStream responseMemoryStream = new MemoryStream();

                StreamWriter sw = new StreamWriter(responseMemoryStream);

                   sw.Write(httpResponse.ToString());

                sw.Flush();

 

                bool isSessionIDContained = httpResponse.Headers.Contains("bs-session-id");

                if (isSessionIDContained == true)

                {

                    IEnumerable<string> sessionEnum = httpResponse.Headers.GetValues("bs-session-id");

                    

                    foreach (string element in sessionEnum)

                    {

                        Console.WriteLine("bs-session-id: " + element);

                        sessionID = element;

                    }

                }

                else if (isSessionIDContained != false)

                {

                    Console.WriteLine("Session ID not found");

                }

            }          

            else

            {

                Console.WriteLine("Failed to log in");

                   Console.WriteLine(httpResponse.ToString());

            }            

        }

 

 

[After Logging Successfully] 

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

자동 생성된 설명

 

 

 

Part 4. Login via Postman

 

[Request Example] 

 

[Response Example: body] 

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

자동 생성된 설명

 

[Response Example: Headers] 

*You must use the ‘be-session-id’ value for other API calls by Postman.

텍스트, 스크린샷, 모니터, 텔레비전이(가) 표시된 사진

자동 생성된 설명


Please input this value in the header of request in other APIs in order to authorize and use other BioStar 2 APIs.