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 help you to create User Groups to your BioStar 2 via using New local API.
This article includes a ‘Create User Groups’ part of a sample application made for those who might need to use the BioStar 2 New Local API. It is a Visual C# console application.
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
- How to Create User Groups
Method | API | What it does | Parameters |
POST
| /api/user_groups | Creates User Groups in BioStar 2 | *Check below |
[POST]: /api/User Groups
[Parameters]
Name | Type | *M/O | Explanation | Value |
Parent_id.id | Int | M | Parent ID |
|
Depth | Int | O | UserGroup Depth |
|
Sync_device_groups | Array | M |
|
|
Sync_devices | Array | M |
|
|
Inherited | Boolean | O | Use UserGroup Inherited |
|
Text | String | O | UserGroup Text |
|
Name | String | M | UserGroup Name |
|
Id | String | O | UserGroup ID | Use Only Number |
State | String | O | UserGroup State | Example: open |
domId | String | O | UserGroup DomId | Example: _easyui_tree_283 |
disabledTreeNode | Boolean | O | Use UserGroup DisabledTreeNode |
|
isTreeView | Boolean | O | Use UserGroup IsTreeView |
|
isRead | Boolean | O | Use UserGroup isRead |
|
isWrite | Boolean | O | Use UserGroup IsWrite |
|
Target | Array & Boolean | M |
| Example: true |
Checked | Boolean | M | Use UserGroup Checked |
|
* M – Mandatory, O – Optional
Part 2. Request Body & Response Model
[Example Value/Parameters Model]
{ "UserGroup": { "parent_id": { "id": 1 }, "depth": 1, "sync_device_groups": [ null ], "sync_devices": [ null ], "inherited": true, "text": "New User Group 1", "name": "New User Group 1", "id": "1011", "state": "open", "domId": "_easyui_tree_283", "disabledTreeNode": true, "isTreeView": true, "isRead": true, "isWrite": true, "target": {}, "checked": false } } |
[Response Model]
{ "UserGroup": { "id": "1369", "name": "New User Group 1" }, "Response": { "code": "1003", "link": "https://support.supremainc.com/en/support/home", "message": "Success" }, "httpResponseStatus": 200 } |
[Response: Fail]
{ "Response": { "code": "10", "link": "https://support.supremainc.com/en/support/home", "message": "Login required." } } |
[Response: Successful]
{ "UserGroup": { "id": "10000286", "name": "API New User Group" }, "Response": { "code": "0", "link": "https://support.supremainc.com/en/support/home", "message": "Success" } } |
Part 3. Console Create User Groups Example
[Create User Groups Method Source Code]
static async void CreateUserGroup() { Console.WriteLine("*****CreateUserGroup Task Started*****"); 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/user_groups";
JavaScriptSerializer serializer = new JavaScriptSerializer();
Console.WriteLine("Enter User Group NAME: "); string name = Console.ReadLine(); Console.WriteLine("Enter User Group DESCRIPTION: "); string description = Console.ReadLine(); string payload = "{\"UserGroup\":{\"parent_id\":{\"id\":1},\"depth\":1,\"sync_device_groups\":[],\"sync_devices\":[],\"inherited\":true,\"text\":\"" + description + "\",\"name\":\"" + name + "\"}}"; 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 User Group Successful."); string httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); Console.WriteLine(httpResponseBody); } else { Console.WriteLine("Create User Group Failed."); Console.WriteLine(httpResponse.ToString()); } } |
[After Create User Groups Successfully]
*Input User Group Name
*Input User Group Name Description
Part 4. Create User Groups 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]
*Only necessary parameters are written in the Request Body
[Response Example: body]