Using the SERVER CODEe component.

The SERVER CODE component allows you to invoke a SERVER CODE script.

Server Code

To start using the SERVER CODE component, you need to select an existing SERVER CODE script to invoke. If you don't see the script in the list, click the Refresh button to update the scripts.

The HTTP method value will be automatically set when a script selection is made. This value should correspond to the same method you used to test the script inside the SERVER CODE editor.

Script Query Parameters

Here you can set any query parameters required for the scrip to run. Query parameters inside the script are usually read via this line of code:

var name = request.get("name");

If you set any query parameters when testing the script in the Script parameters section in SERVER CODE, upon selection of a script in API Express, the query parameter will be automatically inserted.

Script Header Parameters

If the SERVER CODE script requires any header parameters then you should them in this section.

Script Body

If a script will be invoked as POST then you can set its body.

The result variable you will see has to return a valid JSON string that will be used as the body for the script. For example:

result = {"icecream":"Vanilla", "cone":"yes"};

You can write any custom JavaScript as long as you return a valid JSON for the script (using the result variable).

Use previous component allows you to pass the result (response) from the previous component in the flow as the body for this script.

Script Response

In the Script Response section you define the result (response) for the SERVER CODE component. In most cases, you want to use the script response as the response for the component. In this case, click the Generate button. In this popup, you can test the script. You will need to enter any parameters you defined. Click Run Server Code API to test the script.

If the response is OK, click the Import response button to use this result as the response of the SERVER CODE component.