* You can find an introduction to BioStar 2 New Local API in this article : [BioStar 2 API] How To Use BioStar 2 New Local API 

* If you'd like to know more about all the other APIs, please check out this link : https://bs2api.biostar2.com/


 

This article will guide you through registering profile photo for a user via BioStar 2 API.  


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.



We are going to use the following API to register profile photo for a user. 

This API updates user information. 


PUT          /api/users/:id


[Path Variables] 


ParameterTypeRequiredDescription
idNumberYID of user you want to add the fingerprint credential to. 


In this article, I'll only show the body parameters that are related to registering profile photo of a user. 

You can add other parameters if you wish to change/update other user information to this API. 


[Body Parameters] 


ParameterTypeRequiredDescription
photostringYProfile photo. Needs to be in Base64 format. 



[Request Body Example]

{

  "User": {

    "photo ": "/9j/4AAQSKZJRgABAQEA…"

  }

}

* If you want to unregister an existing profile photo, run the same API but leave the photo parameter empty such as "photo" : ""

[Response: Fail]

{

    "Response": {

        "code": "65675",

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

        "message": "not defined"

    }

}

[Response: Successful]

{

    "Response": {

        "code": "0",

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

        "message": "Success"

    }

}

 


C# Console App Example

 

The below source code has a function to convert the image path to the ‘Base64’ format. 

You just have to enter the image’s {path\imagename.format} in order to register user profile photo.

static async void RegisterProfilePhoto()  

        {

            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));

            ListUsers();

            Console.WriteLine("Enter USER ID to register profile photo: ");

            string userid = Console.ReadLine();

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

            string photopath = "";

            String file = "";

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            Console.WriteLine("Enter photo path: *Leave EMPTY to UNREGISTER Current Profile Photo");

            photopath = Console.ReadLine();

            if(photopath != "")

            {

                Byte[] bytes = File.ReadAllBytes(photopath);

                file = Convert.ToBase64String(bytes);

            }

 

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

            payload2 = payload2 + "\"photo\": \"" + file + "\"}}";

            Console.WriteLine(payload2);

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

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

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

 

            if (httpResponse.IsSuccessStatusCode == true)

            {

                if (photopath != "")

                {

                    Console.WriteLine("Profile Photo has been registered.");

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

                       Console.WriteLine(httpResponseBody);

                }

                else{

                    Console.WriteLine("Profile Photo has been unregistered.");

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

                       Console.WriteLine(httpResponseBody);

                }

            }

            else

            {

                Console.WriteLine("Failed to register Profile Photo.");

                   Console.WriteLine(httpResponse.ToString());

            }

        }

 

When you run the above code : 

Please make sure to put the appropriate inputs when prompted. 

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

자동 생성된 설명

[After registering Successfully] 

 

 


Postman Example

 

[Request Example] 

[Response Example] 

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

자동 생성된 설명