Installation Parameters

The FDK enables you to define and use parameters whose values app users can set when they install an app. These parameters are termed installation parameters or iparams. To define and use iparams:

  1. Configure the iparams. During app installation, the configured iparams are displayed on an installation page. App users can enter appropriate values for the iparams and click INSTALL. The entered values are validated and saved.
  2. In the app logic, use the client.iparams.get(), client.iparams.get(iparam_key), or the Request method (for secure iparams), to retrieve the iparam values.
    Note: To prevent exposure of sensitive iparam information, secure iparams can only be retrieved by the Request method.

For serverless apps, the configured iparams are passed as part of event payloads. The app logic can retrieve the iparams’ values from the payload.

Configure
  1. From your app’s root directory, navigate to the iparam.json file.
  2. Configure iparams by using the following sample format.
Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{ "contact": { "display_name": "Contact Details", "description": "Please enter the contact details", "type": "text", "required": true }, "age": { "display_name": "Age", "description": "Please enter your age in years", "type": "number" }, "contactType": { "display_name": "Contact Type", "description": "Please select the contact type", "type": "dropdown", "options": [ "Phone", "Email" ], "default_value": "Email" }, "domainName": { "display_name": "Domain Name", "description": "Please enter your domain name", "type": "domain", "type_attributes": { "product": "freshteam" }, "required": true }, "apiKey": { "display_name": "API Key", "description": "Please enter your api_key", "type": "api_key", "secure": true, "required": true, "type_attributes": { "product": "freshteam" } } }
EXPAND ↓

Configure each iparam as a JSON object with the following attributes.

ATTRIBUTE NAME DATA TYPE DESCRIPTION
display_name
MANDATORY
string Identifier of a parameter on the installation page.
description string Helper text that is displayed along with the parameter, on the installation page. The description can include examples.
type
MANDATORY
string Type of input field displayed, for the iparam, on the installation page.
Possible values: text, paragraph, dropdown, email, number, phone_number, date, url, radio, checkbox, multiselect, domain, api_key
For information on the available types of input fields, see Types.
options array of strings List of values displayed on the installation page, if the iparam’s input field type is radio, multiselect, or dropdown.
default_value string Preselected value(s) (from options) displayed on the installation page, if the iparam’s input field type is radio, multiselect, or dropdown.
required boolean Specifies whether the iparam is displayed as a mandatory parameter. An asterix is displayed next to the the parameter on the installation page.
Possible values: true, false
visible boolean Specifies whether the iparam is displayed on the installation page.
Possible values: true, false
Example Copied Copy
1
2
3
4
5
6
7
8
9
{ "contact": { "display_name": "Contact Details", "description": "Please enter the contact details", "type": "text", "required": true, "visible": true } }
secure boolean Specifies whether the iparam is used to collect sensitive data, which has to be protected from exposure through the app’s front-end components.
Possible values: true, false
Example Copied Copy
1
2
3
4
5
6
7
8
{ "apiKey": { "display_name": "Api Key", "type": "text", "required": true, "secure": true } }

Note: Sensitive iparams, such as key, auth, token, secret, are detected when running the fdk validate and fdk pack commands and a warning is displayed to mark them as secure.
For comprehensive information on secure iparams, read the securing sensitive installation parameters blog post.
regex object Expression(s) used to validate a parameter value entered in the installation page. The regex validation is performed in addition to the default field-type validation. If the validation fails, an error message is displayed. The regex expression and associated error message formats are as follows:
"<regex_name>":"<valid_regex_expression>"
"<regex_name>":"<error_message>"
Example regex expression to verify that the age entered is between 10 and 99 Copied Copy
1
2
3
4
5
6
7
8
9
10
11
{ "Age": { "display_name": "Age", "description": "Please enter your age in years", "type": "text", "regex": { "age-limit": "[1-9][0-9]",  "age-limit-error": "The age must be between 10-99" } } }
EXPAND ↓
type_attributes object Freshworks’ product to which the app belongs. This attribute is required if the iparam’s input field type is domain or api_key.
events array of objects HTML events and associated callbacks, specified as an array of JSON objects. Each JSON object is an "<event name>": "<callback function name>" pair. If an event is associated with an iparam, when the event occurs in the installation page, the associated callback function is invoked.
Note: Currently, only change events are supported. Therefore, ensure that the <event name> is change.
For information on how to define callback functions, see the make your installation page dynamic section.

Note: Alternatively, you can use the generate command to interactively configure iparams.
Types

In the iparam.json file, the type parameter value should be one of the following.

text - A single-line text field is displayed on the installation form.

Copied Copy
1
2
3
4
5
6
7
8
{ "Employee-Name": { "display_name": "Employee Name", "description": "Please enter the employee details", "type": "text", "required": true } }

paragraph - A multi-line text field is displayed.

Copied Copy
1
2
3
4
5
6
7
8
{ "Employee-Address": { "display_name": "Employee address", "description": "Please enter the employee address", "type": "paragraph", "required": true } }

dropdown - A drop-down list from which a single option can be selected is displayed. The values specified in the options attribute of the iparams.json file are used to populate the drop-down list.

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
{ "Employee-Type": { "display_name": "Employee Type", "description": "Please select the employee type", "type": "dropdown", "options": [ "Full time", "Contract" ], "default_value": "Full time" } }
EXPAND ↓

email - A single-line text field to enter a valid email address is displayed.

Copied Copy
1
2
3
4
5
6
7
8
{ "Official-Email": { "display_name": "Official Email", "description": "Please enter your email address", "type": "email", "required": true } }

number - A numeric field that accepts integers upto 10 digits is displayed.

Copied Copy
1
2
3
4
5
6
7
8
{ "Age": { "display_name": "Age", "description": "Please enter your age in years", "type": "number", "required": true } }

phone_number - A single-line text field to enter a valid phone number is displayed.

Copied Copy
1
2
3
4
5
6
7
8
{ "Phone-Number": { "display_name": "Phone Number", "description": "Please enter your phone number with the country code", "type": "phone_number", "required": true } }

date - A field to enter a valid date (or pick a date by using a date picker) is displayed.

Copied Copy
1
2
3
4
5
6
7
8
{ "Date-of-Birth": { "display_name": "Date of Birth", "description": "Please enter your date of birth", "type": "date", "required": true } }

url - A single-line text field to enter a valid URL is displayed.

Copied Copy
1
2
3
4
5
6
7
8
{ "Team-Domain": { "display_name": "Team Domain", "description": "Please enter your team domain web address", "type": "url", "required": true } }

radio - Radio buttons along with values specified in the options attribute of the iparams.json file are displayed.

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
{ "Employee-Type": { "display_name": "Employee Type", "description": "Please select the employee type", "type": "radio", "options": [ "Full time", "Contract" ], "default_value": "Full time" } }
EXPAND ↓

checkbox - A checkbox is displayed next to the iparam.

Copied Copy
1
2
3
4
5
6
7
8
{ "Archive-Details": { "display_name": "Archive Details", "description": "Check this option if the employee details are to be archived", "type": "checkbox", "default_value": true } }

multiselect - A list from which users can select one or more options, is displayed. The values specified in the options attribute of the iparams.json file are used to populate the list.

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{ "Contact-Methods": { "display_name": "Contact Methods", "description": "Please select the preferred contact methods", "type": "multiselect", "options": [ "Phone", "Mobile", "Twitter ID", "Email" ], "default_value": ["Mobile", "Email"] } }
EXPAND ↓

domain - An input box to enter the account name part of a domain URL is displayed. By default, the protocol and domain name part of the URL are displayed in the input box and are not editable. The domain name is generated based on the type_attributes.product value that is specified as part of the domain_name JSON object.

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
{ "domain_name": { "display_name": "DomainName", "description": "Please enter your domain name", "type": "domain", "type_attributes": { "product": "freshteam" }, "required": true } }
EXPAND ↓

api_key - A single-line text box to enter the product’s API key is displayed.

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
{ "api_key": { "display_name": "api_key", "description": "Please enter your api_key", "type": "api_key", "secure": true, "required": true "type_attributes": { "product": "freshteam" } } }
EXPAND ↓

Note: The iparams of the domain and api_key types are validated when the app is installed.

Make your installation page dynamic

When you configure iparams, you can use the events attribute to build a dynamic installation page to collect values for the installation parameters. To do this:

  1. From the app’s root directory, navigate to the config/iparams.json file.
  2. Include the events attribute as part of the iparam configuration. Specify an HTML event and a corresponding callback function, as a JSON object of "<event name>": "<callback function name>" pair by using the following sample format. Copied Copy
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    { "firstname": { "display_name": "First Name", "description": "Please enter your business name", "type": "text", "required": true, "events": [ {"change": "firstnameChange"} ] }, "multiselect": { "display_name": "Other Details", "description": "Please select values", "type": "multiselect", "required": true, "options": [ "opt1", "opt2", "opt3" ] } }
    EXPAND ↓
  3. From the app’s root directory, navigate to the config directory and create the assets/iparams.js file.
  4. Define the callback function by using the following sample format.
    Note: Ensure that the callback function’s name is the <callback function name> specified in the iparams.json file.
    Copied Copy
    1
    2
    3
    4
    5
    function firstnameChange(arg) { //validation logic and subsequent action performed //arg is the iparam value passed to the callback function console.log(arg); }
    EXPAND ↓
  5. To set or modify the attribute value of an iparam and add validations to an iparam, based on the input value of another iparam, use utils.set(); in the callback function definition.
    For more information, see iparam utility methods.
  6. To retrieve the value of an iparam, based on the input value of another iparam, use utils.get(); in the callback function.
    For more information, see iparam utility methods.
  7. To validate a value entered for an iparam or use the value entered to perform some action (such as an API call), validate the value returned, and display a success or failure message, use return; in the callback function.
    For more information, see return;.

When an app user enters or modifies an iparam value, the change event is triggered and the iparam value is passed to the callback function. The value is validated and subsequent actions are performed. The validation and actions are based on the logic defined in the callback function.

iparams utility methods

The FDK consists of in-built utility methods that enable you to set or modify the attribute value of an iparam, add validations to an iparam, and retrieve the value of an iparam during run-time. You can use the following methods in your callback function.

utils.set();

Enables you to set or modify the iparam attributes that are displayed in the installation page or impart further validations to the iparams.

Format Copied Copy
1
utils.set(<iparam_key>, {<attribute>: <value>});
EXPAND ↓

<iparam_key> identifies the iparam that is modified or validated when the change event occurs.
<attribute> specifies the iparam’s installation page attribute that is modified or the validation set for the iparam. <value> specifies the value that is set for <attribute> and must adhere to the data type of <attribute>.

For an iparam identified by <iparam_key>, <attribute> can be any of the following values.

Note: For an iparam, in utils.set();, you can specify any number of <attribute>: <value> pairs.

<attribute> DATA TYPE DESCRIPTION
value string

array of strings (for iparams of the multiselect type)
Enables you to set a value for the iparam.

For a multiselect iparam, enables you to set certain values as selected options. On the installation page, the selected options are populated in the iparam’s input field.
label string Enables you to modify the display_name attribute value of the iparam.
visible boolean Enables you to hide the iparam from the installation page.
disabled boolean Enables you to disable the iparam on the installation page.
required boolean Enables you to modify the required attribute value of the iparam.
hint string Enables you to modify the description attribute value of the iparam.
values
Valid only for iparams of the radio, multiselect, and dropdown types.
array of strings Enables you to modify the options attribute value of the iparam.
min
Valid only for iparams of the number type.
number Enables you to set a validation for the minimum value that can be entered for the iparam.
max
Valid only for iparams of the number type.
number Enables you to set a validation for the maximum value that can be entered for the iparam.

value

Sample code to set the value of the lastname iparam to the value the app user specifies for the firstname iparam.

iparams.json

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{ "firstname": { "display_name": "First Name", "description": "Please enter your business name", "type": "text", "required": true, "events": [ {"change": "firstnameChange"} ] }, "lastname": { "display_name": "Last Name", "description": "Please enter your last name", "type": "text", "required": false } }
EXPAND ↓
iparams.js Copied Copy
1
2
3
function firstnameChange(arg) { utils.set(lastname, {value: arg}); }
EXPAND ↓

Sample code to populate the multiselect iparam field with a list of options, if the app user specifies a value for the firstname iparam.

iparams.json

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{ "firstname": { "display_name": "First Name", "description": "Please enter your business name", "type": "text", "required": true, "events": [ {"change": "firstnameChange"} ] }, "multiselect": { "display_name": "Other Details", "description": "Please select values", "type": "multiselect", "required": true, "options": [ "opt1", "opt2", "opt3" ] } }
EXPAND ↓

iparams.js

Copied Copy
1
2
3
function firstnameChange(arg) { utils.set(multiselect, {value: [opt1,opt2]}); }
EXPAND ↓

visible

Sample code to hide the lastname iparam from the installation page, if the app user specifies a value for the firstname iparam.

iparams.json

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{ "firstname": { "display_name": "First Name", "description": "Please enter your business name", "type": "text", "required": true, "events": [ {"change": "firstnameChange"} ] }, "lastname": { "display_name": "Last Name", "description": "Please enter your last name", "type": "text", "required": false } }
EXPAND ↓

iparams.js

Copied Copy
1
2
3
function firstnameChange(arg) { utils.set(lastname, {visible: false}); }
EXPAND ↓

Sample code to display the lastname iparam in the installation page, if the app user enters a valid value for the firstname iparam and to hide the lastname iparam from the installation page, if the app user deletes the entered value.

iparams.json

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{ "firstname": { "display_name": "First Name", "description": "Please enter your business name", "type": "text", "required": true, "events": [ {"change": "firstnameChange"} ] }, "lastname": { "display_name": "Last Name", "description": "Please enter your last name", "type": "text", "required": false } }
EXPAND ↓

iparams.js

Copied Copy
1
2
3
function firstnameChange(arg) { utils.set(lastname, {visible: arg !== ‘’}); }
EXPAND ↓

values

Sample code to modify the list of options available for the multiselect iparam and display_name to Hobbies, if the app user enters a value for the firstname iparam.

iparams.json

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{ "firstname": { "display_name": "First Name", "description": "Please enter your business name", "type": "text", "required": true, "events": [ {"change": "firstnameChange"} ] }, "lastname": { "display_name": "Last Name", "description": "Please enter your last name", "type": "text", "required": false } "multiselect": { "display_name": "Other Details", "description": "Please select values", "type": "multiselect", "required": true, "options": [ "opt1", "opt2", "opt3" ] } }
EXPAND ↓

iparams.js

Copied Copy
1
2
3
function firstnameChange(arg) { utils.set(multiselect, {values: [Travelling, Swimming, Reading books], label: Hobbies}); }
EXPAND ↓

min and max

Sample code to set a validation criteria and to modify display_name of the age iparam, if the app user enters a value for the firstname iparam. When the app user enters a value for the age iparam, if the value fails to meet the validation criteria, an error message is displayed.

iparams.json

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{ "firstname": { "display_name": "First Name", "description": "Please enter your business name", "type": "text", "required": true, "events": [ {"change": "firstnameChange"} ] }, "age": { "display_name": "Last Name", "description": "Please enter your last name", "type": "number", "required": false } }
EXPAND ↓

iparams.js

Copied Copy
1
2
3
function firstnameChange(arg) { utils.set(age, {label: Age in years, min: 18, max: 65}); }
EXPAND ↓

utils.get();

Enables you to identify an iparam and retrieve its value during run-time.

Format Copied Copy
1
utils.get(<iparam_key>);
EXPAND ↓

<iparam_key> identifies the iparam whose value is retrieved when the change event occurs.

return;

Returning an error message, clears the value entered for the iparam and thereby invalidates the field. Returning an empty string or not returning a value, passes the validation as a success.

Format Copied Copy
1
return <validation criteria> ? <Success Message>: <Error Message>;
EXPAND ↓

Sample code to make an API call based on the value entered for the APIKey iparam, validate if an empty value is returned by the API call, and if so, display an error message.

iparams.json

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{ "APIKey": { "display_name": "API Key", "description": "Please enter your api key", "type": "api_key", "secure": true, "required": true, "type_attributes": { "product": "freshteam" }, "events": [ {"change": "APIKeyChange"} ] } }
EXPAND ↓

iparams.js

Copied Copy
1
2
3
4
5
function APIKeyChange(arg) { //API call by using arg which is the API Key entered by the app user //value is the response returned by the API call return value==‘’ ? Invalid API Key: ‘’; }
EXPAND ↓

Sample code to invoke a third-party API based on the value entered for the acc_id iparam and validate the iparam field asynchronously by using the callback functionality.

iparams.json

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
{ "acc_id": { "display_name": "Account ID", "description": "Please enter your Acc. ID", "type": "text", "required": true, "events": [{ "change": "checkAccountID" }] } }
EXPAND ↓

iparams.js

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* global app, client, utils */ app.initialized().then( function(_client) { //If successful, register the app activated and deactivated event callback. window.client = _client; }, function(error) { //If unsuccessful console.log(error); } ); /* Using the iparam callback function, we are validating the iparam value after a third-party API call. */ /* Payload and other options can be specified using ‘options’. */ function checkAccountID(newValue) { var url = "https://example.com/verify"; var options = { body: JSON.stringify({ param: newValue }) }; var p = new Promise(function(resolve, reject) { client.request.post(url, options).then( function(data) { // Upon success resolve(); }, function(error) { // Upon failure - send an appropriate validation error message reject("The account does not exist."); } ); }); return p; }
EXPAND ↓

Retrieve

To retrieve the configured iparams and to use them in the app components, use the following methods:

  • client.iparams.get()
  • client.iparams.get(iparam_key)

Note:
1. Secure iparams can be used only with Request Method to make HTTP requests.
2. For serverless apps, iparams are available in the payload received with each event.


client.iparams.get() - This method returns all the configured installation parameters except secure iparams.

Copied Copy
1
2
3
4
5
6
7
8
9
10
client.iparams.get().then ( function(data) { // success output // "data" is returned with the list of all the iparams }, function(error) { console.log(error); // failure operation } );

Sample Response

Copied Copy
1
2
3
4
5
6
{ "employee": "rachel@freshteam.com", "employee_type": "Full time", "request_domain": "sample.freshteam.com", "subdomian": "sample" }

client.iparams.get(iparam_key) - This method identifies an iparam by the iparam key specified and returns the value corresponding to the iparam. If you try to retrieve a secure iparam, an error message is displayed.

Copied Copy
1
2
3
4
5
6
7
8
9
10
client.iparams.get("employee").then ( function(data) { // success output // "data" is returned with the value of the "employee" attribute. }, function(error) { console.log(error); // failure operation } );

Sample Successful Response

1
2
3
{ "employee": "rachel@freshteam.com" }

Sample Failure Response

1
2
3
{ "message": "Could not find an installation parameter that matches this key." }
Test

To test the configured installation parameters:

  1. From the command prompt, navigate to the app project folder, and run the following command: $ fdk run If the app contains an installation page, the following message is displayed: To test the installation page, visit - http://localhost:10001/custom_configs
  2. Navigate to the specified location. The installation page is displayed.
  3. Enter appropriate values in the fields and click INSTALL to test the installation page.