This article will guide you through viewing/creating/updating custom user fields. 



Before We Get Started


For an intro to BioStar 2 API, please refer to the following article : [BioStar 2 API] How To Use BioStar 2 New Local API

For more information on all of the BioStar 2 APIs, please refer to the following document: https://bs2api.biostar2.com/



What Are Custom Fields?


Before we get started, ensure you have access to your BioStar 2 Settings. 

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



In this article, I will guide you through achieving two main functionalities related to custom user fields: 

  1. How to view the list of all existing custom user fields.
  2. How to create or update custom user fields.
     

Part 1. How To View the List of All Existing Custom User Fields

 

To retrieve the list of custom user fields, use the following API endpoint:

GET             /api/setting/custom_fields

 

[EXAMPLE]

Currently, in this BioStar 2 server, there are two custom user fields as you see in the below screenshot (1-nickname, 2-zip code). 


After calling the above API, you will receive the following response. 

As you can see, it shows two results, one with 'id' - "1" and 'name' - "nickname", and another with 'id' - "2" and 'name' - "zip code". 

'What is the meaning of each field in the API response?'

- ‘total’: Number of Custom User Field items

- ‘id’: Custom User Field ID. Please take note of this value if you want to edit this custom user field in Part 2 below. 

- ‘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.

 


Part 2. How to Create or Update Custom User Fields

 

To create or update custom user fields, use the following API endpoint:

PUT             /api/setting/custom_fields

 

[Body Parameters]

ParameterTypeRequiredDescription
idNumberYID of the custom field.
ONLY required if you are modifying an existing custom user field. Do NOT add it if you want to create a new custom user field.
orderNumberYOrder sequence of the custom field.
nameStringYName of the custom field.
typeNumberY0: Text Input, 1: Number Input, 2: Combo Box.
dataStringNCombo Box options, use (;) as separator of each value.
Use if you are trying to create Combo Box type custom user field. 


 

 [Request Body Example]

{

       "CustomFieldCollection": {

           "rows": [

               {

                "id": "1",

                "name": "nickname-change",

                "type": "0",

                "order": "1"

            },

               {

                "order": 3,

                "name": "vehicle",

                "type": 2,

                "data": "yes;no"

            }

           ]

    }

}


 * If you want to update an existing custom user field, you need to add the "id" field. You can obtain this "id" field from the response of GET /api/setting/custom_fields in Part 1 of this article. * 


* Note that when you are creating a new custom user field, you don't need "id" field. Also note that because I put "type" : 2 (Combo Box), I added "data" field for the combo box options. I added two options, "yes" and "no", but you can add more if you want to. * 


[Response Example]

{

       "Response": {

           "code": "0",

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

           "message": "Success"

    }

}

 


After running the above API, if we check BioStar 2, you can see that the first custom field's name has been updated to "nickname-change", and there is a new custom user field, "vehicle".