This article will guide you through creating a door 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 create a door in 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 

 

[POST]:     /api/doors

[Parameters]

ParameterTypeRequiredDescription
nameStringYName of the door
descriptionStringNDescription of the door
door_group_id:idNumberYID of the Door Group which the door will be under
open_timeoutNumberNConfigure the maximum allowed time for the door to remain open. Default: 10.
open_durationNumberNSet the duration for which the door will remain open after a user authentication is completed. When the authentication is successful, the relay will be activated for the set time. When this time elapses, the relay no longer sends the signal to the door. Open Time may vary depending on the type of door lock used.
open_onceBooleanNLock when door is closed: When the door sensor detects that the door is closed, the door is locked. Set this option to false if unconditional_lock is true. Set true to enable this parameter. Default: false.
unconditional _lockBooleanNUse Automatic Door: When using an automatic door as an entrance door, a relay can operate regardless of the status of a door sensor. Set this option as false if open_once is set to true.
relay_output_id:device_id:idNumberYDevice ID which the relay will be used to control the door lock.
relay_output_id:relay_indexNumberYRelay index of the device which will be used.
exit_button_input_id:device_id:idNumberYDevice ID which will be used as exit control.
exit_button_input_id:input_indexNumberYExit index of the device which will be used.
exit_button_input_id:typeBooleanY1: Normally Closed, 0: Normally Open
sensor_input_id:device_id:idNumberYDevice ID which will be used as sensor control.
sensor_input_id:input_indexNumberYSensor index of the device which will be used.
sensor_input_id:typeBooleanY1: Normally Closed, 0: Normally Open
sensor_input_id:apb_use_door_sensorBooleanYSet whether to use the door sensor when using Entry Confirmed APB.



Part 2. Request Body & Response Model


[Example Value/Parameters Model]

{

  "Door": {

    "exit_button_input_id": {

      "device_id": {

        "id": 635,

        "name": "Base64: RDQQFJYAVUYvFXsEIzIQC1QYbodkHe..."

      },

      "input_index": 0,

      "type": "0",

      "supervised": ""

    },

    "sensor_input_id": {

      "device_id": {

        "id": 635,

        "name": "Base64: RDQQFJYAVUYvFXsEIzIQC1QYbodkHe..."

      },

      "input_index": 0,

      "type": "0",

      "supervised": ""

    },

    "antitailsensor_input_id": {

      "device_id": {},

      "type": "0"

    },

    "open_duration": 3,

    "dual_authentication": {

      "device": "1",

      "approval_type": "1",

      "timeout": 15,

      "schedule_id": {

        "id": "1"

      },

      "approval_groups": [

        null

      ]

    },

    "open_once": "false",

    "unconditional_lock": "true",

    "door_group_id": {

      "id": 1,

      "name": "All Doors"

    },

    "entry_device_id": {

      "id": 635,

      "name": "Base64: RDQQFJYAVUYvFXsEIzIQC1QYbodkHe...",

      "device_type_id": {

        "id": 18

      }

    },

    "trigger_actions": [

      {

        "input_event_id": {

          "code": "22528"

        },

        "output_device_id": {

          "id": 635,

          "name": "Base64: RDQQFJYAVUYvFXsEIzIQC1QYbodkHe...",

          "device_type_id": {

            "id": 18

          },

          "status": "2",

          "rs485": {

            "mode": "1",

            "channels": [

              null

            ],

            "parent_rs485_info": ""

          },

          "device_group_id": {

            "id": 1,

            "name": "All Devices"

          },

          "version": {

            "firmware": "1.1.0",

            "product_name": "BLN2-OAB"

          },

          "lan": {

            "ip": "192.168.12.165",

            "connection_mode": "0"

          },

          "tna": {

            "mode": "3",

            "required": "false",

            "fixed_code": "1",

            "tna_keys": [

              {

                "enabled": "false",

                "label": "",

                "icon": "0"

              }

            ]

          },

          "slave_devices": [

            null

          ],

          "packet_version": 2,

          "iconCls": "dvBioLiteN2 sync_error",

          "deviceData": {

            "id": 635,

            "name": "Base64: RDQQFJYAVUYvFXsEIzIQC1QYbodkHe...",

            "device_type_id": {

              "id": 18

            },

            "status": 2,

            "rs485": {

              "mode": "1",

              "channels": [

                null

              ],

              "parent_rs485_info": ""

            },

            "device_group_id": {

              "id": 1,

              "name": "All Devices"

            },

            "version": {

              "firmware": "1.1.0",

              "product_name": "BLN2-OAB"

            },

            "lan": {

              "ip": "192.168.12.165",

              "connection_mode": "0"

            },

            "tna": {

              "mode": "3",

              "required": "false",

              "fixed_code": "1",

              "tna_keys": [

                {

                  "enabled": "false",

                  "label": "",

                  "icon": "0"

                }

              ]

            },

            "slave_devices": [

              null

            ],

            "packet_version": 2,

            "iconCls": "dvBioLiteN2 sync_error"

          },

          "sound": true

        },

        "output_type": 2,

        "sound_index": 4,

        "stop_flag": 1,

        "$$hashKey": "object:3207"

      }

    ],

    "relay_output_id": {

      "device_id": {

        "id": 635

      },

      "relay_index": 0

    },

    "open_timeout": 3,

    "name": "d22",

    "door_anti_passback": {}

  }

}

 

[Response Model]

{

     "DoorCollection": {

       "total": "1",

       "rows": [

         {

           "id": "3",

           "name": "d22"

         }

       ]

     },

     "DeviceResponse": {

       "rows": [

         {

           "id": "541530960",

           "seq": "37",

           "command": "0x500(BS2_CMD_SET_DOOR)",

           "code": "64230"

         }

       ],

       "result": "false"

     },

     "Response": {

       "code": "0",

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

       "message": "Success"

     },

     "httpResponseStatus": 200

}

 

[Response Example: Fail]

{

       "Response": {

           "code": "10",

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

           "message": "Login required."

       }

}

 

[Response Example: Successful]

{

     "DoorCollection": {

       "total": "1",

       "rows": [

         {

           "id": "34",

           "name": "Door3223"

         }

       ]

     },

     "Response": {

       "code": "0",

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

    "message": "Success"

     }

}

 


Part 3. Console Create Door Example

 

[Create Door Method C# Source Code Example] 

static async void CreateDoor()

        {

            Console.WriteLine("*****CreateDoor Task Started******");

            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(BioStarIP), new Cookie("bs-session-id", sessionID));

            string resourceAddress = BioStarIP + "/api/doors";

 

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            Console.WriteLine("Enter Door Name: ");

            string name = Console.ReadLine();

            ListDevices();

            Console.WriteLine("Enter Relay Device ID: ");

            string RelayDeviceID = Console.ReadLine();

            string payload = "{{\"Door\":{\"door_group_id\":{\"id\":1,\"name\":\"AllDoors\"},\"entry_device_id\":{},\"relay_output_id\":{\"device_id\":{\"id\":" + RelayDeviceID + "},\"relay_index\":1},\"open_timeout\":3,\"name\":\"" + name + "\",\"door_anti_passback\":{}}}}";

            Console.WriteLine(payload);

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

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

 

            if (httpResponse.IsSuccessStatusCode == true)

            {

                Console.WriteLine("Create Door Successful.");

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

                   Console.WriteLine(httpResponseBody);

            }

            else

            {

                Console.WriteLine("Create Door Failed.");

                   Console.WriteLine(httpResponse.ToString());

            }

        }

 

[Running the above code] 

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

자동 생성된 설명

 


 

Part 4. Create Door via Postman

 

[Request Example: Headers] 

* Please note that you must obtain the ‘be-session-id’ value from the response header of the Login API call and input it in the request header of other APIs in order to authenticate other API calls.

텍스트, 모니터, 스크린샷, 화면이(가) 표시된 사진

자동 생성된 설명


[Request Example] 

텍스트, 스크린샷, 모니터, 화면이(가) 표시된 사진

자동 생성된 설명

 

[Response Example: body] 

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

자동 생성된 설명