For information about using BioStar 2 New Local API, please refer to the article below.
[BioStar 2 API] How to use and start BioStar 2 Local API Server
If you go to your BioStar 2 Settings -> Server, you can set your own Custom User Field. Custom User Field is a user-defined information which can be used for registered USERS of your BioStar 2.
For example, you can add ‘Birthday’ or ‘NickName’ information in addition to the basic USER information(such as Name, Department, Email, ID…etc.)
You can add Custom User Field by using basic functions of your BioStar 2, following the article below:
How to Create Custom User Fields
And you can also add Custom User Field by using BioStar 2 New Local API. We will look into 2 API functions related to Custom User Field:
- How to Search for the Custom User Field
- How to Update(or Add) the Custom User Field
*Above API calls is not listed on the swagger yet.(2021-09-30)
1. How to Search for the Custom User Field
Method | API | What it does | Parameters |
GET | /api/setting/custom_fields | Search for all the Custom User Fields in BioStar 2 |
|
[GET] /api/setting/custom_fields
[Parameters]
Name | Type | *M/O | Explanation | Parameter Type |
|
|
|
|
|
* M – Mandatory, O – Optional
[Request Body]
|
[Response]
{ "CustomFieldCollection": { "total": "3", "rows": [ { "id": "1", "name": "Birthday", "type": "0", "order": "1" }, { "id": "8", "name": "CUF_Number", "type": "1", "order": "2" }, { "id": "9", "name": "CUF_Combo", "type": "2", "order": "3", "data": "Option 1; Option 2; Option 3" } ] }, "Response": { "code": "0", "link": "https://support.supremainc.com/en/support/home", "message": "Success" } } |
- ‘total’: Number of Custom User Field items
- ‘id’: Custom User Field ID
- ‘name’: Custom User Field Name
- ‘type’: Type of Custom User Field. 0 = text, 1 = number, 2 = combo
- ‘data’: This parameter only exists for ‘combo’ fields. It indicates the choice options.
2. How to Update(or Add) the Custom User Field
Method | API | What it does | Parameters |
PUT | /api/setting/custom_fields | Update the Custom User Fields in BioStar 2 | Id, name, type, order, data, enable |
[PUT] /api/setting/custom_fields
[Parameters – for already existing fields]
Name | Type | *M/O | Explanation |
Id | String | M | Custom User Field ID |
Name | String | M | Custom User Field Name |
Type | String | M | Custom User Field Type 0 = Text 1 = Number 2 = Combo |
Order | String | O | Custom User Field Combo |
* M – Mandatory, O – Optional
[Parameters – for New Custom User Fields to be added]
Name | Type | *M/O | Explanation |
Order | String | O | Custom User Field Combo |
Name | String | M | Custom User Field Name |
Type | String | M | Custom User Field Type 0 = Text 1 = Number 2 = Combo |
Enable | True/False | M | Whether to use or not. Set it as ‘true’ for use. |
* M – Mandatory, O – Optional
[Request Body]
{ "CustomFieldCollection": { "total": "3", "rows": [ { "id": "1", "name": "Birthday", "type": "0", "order": "1" }, { "id": "8", "name": "CUF_Number", "type": "1", "order": "2" }, { "id": "9", "name": "CUF_Combo", "type": "2", "order": "3", "data": "Option 1; Option 2; Option 3; Option 4" }, { "order": 4, "name": "CUF_NEW", "type": 0, "enable": true } ] } } |
*yellow indicates the new Custom User Field to be added
[Response]
{ "Response": { "code": "0", "link": "https://support.supremainc.com/en/support/home", "message": "Success" } } |
*You can see the Custom User Field you’ve just added on your BioStar2.
3. Example – Get user information with the custom field
When you call [GET] /api/users/{user_id}, you can check the custom field values of the user selected.
{ "UserCollection": { "total": "6", "rows": [ { "user_id": "2", "name": "Sharon", "gender": "0", "photo_exists": "false", "pin_exists": "false", "login_id": "sharon", …(skipped) "user_custom_fields": [ { "item": "1990-02-31", "user_id": { "user_id": "2", "name": "Sharon" }, "custom_field": { "id": "1", "name": "Birthday", "type": "0", "order": "1" } }, { "item": "33333", "user_id": { "user_id": "2", "name": "Sharon" }, "custom_field": { "id": "8", "name": "CUF_Number", "type": "1", "order": "2" } }, { "item": "Option 1", "user_id": { "user_id": "2", "name": "Sharon" }, "custom_field": { "id": "9", "name": "CUF_Combo", "type": "2", "order": "3" } }, { "item": "New Field", "user_id": { "user_id": "2", "name": "Sharon" }, "custom_field": { "id": "10", "name": "CUF_NEW", "type": "0", "order": "4" } } ] } ] }, … "Response": { "code": "0", "link": "https://support.supremainc.com/en/support/home", "message": "Success" } } |
[Result shown in the swagger]