Plugins are places in Socotra where system behavior can be customized with user-created scripts written in Javascript.


See the Scripts API topic for information about deploying scripts and retrieving logs from scripts.

Script Format

Each plugin is implemented in a javascript file with a predefined name. A data object with a predefined format is passed to a function, again with a predefined name, and the response is sent back using the javascript return statement. For example, a simple implementation for the underwriting decision plugin can look like this:

// in underwriter.js
function getUnderwritingResult(data)
  console.log("Hello underwriting world!");

  return {
    "decision": "accept",
    "notes": [ "Everyone wins!" ]
exports.getUnderwritingResult = getUnderwritingResult;

In this example, the file is underwriter.js, the function name is getUnderwritingResult, and the return object has a decision string property and a notes string array property. The exports statement at the end is required.

Script Data

Each plugin is passed a data object with information specific to that plugin. See the feature guide for the specific plugin for information about the structure of the data object.


To ensure full precision in passed data, numeric values in the data object are passed as strings. You can use the javascript parseInt or parseFloat functions to convert these values to standard javascript numeric values as needed.

Table Lookups

To lookup information in a table, use the function:

socotraApi.tableLookup(configVersion, tableName, key)

The value returned will be a string but can be converted to other javascript types as desired.


The configVersion parameter will be used in a future version of Socotra. For now, pass the value 0. The table referenced by the tableName paramater must have two columns named key and value.

Script Deployment

Scripts may be uploaded in either of two ways:

  • Embedded in a configuration deployment. There will be top-level folder in the configuration zip file called /scripts which will contain branch folders and javascript files below.

  • Uploaded directly to the scripts deployment endpoint with a zip file in multipart form format. With this endpoint, include the structure below what would have gone in the configuration /scripts folder.

To use the simple underwriting decision plugin example above, the scripts zip file would have the following file:


Product Script Branch Selection

In the /products/{productName}/policy.json configuration file, the property scriptsBranch is used to tell Socotra to use the scripts in the given branch. For example, if scripts have been deployed with a file called /master/underwriter.js, then adding the property "scriptsBranch": "master" to policy.json will enable the underwriting decision plugin for that property.


In a javascript plugin script, the javascript method console.log can be used to log messages which can be retrieved later.

To retrieve logs, first call the scripts log query endpoint (with a QueryRequest object to filter based on desired values) to retrieve a list of top-level LogEvent objects (there will be one per plugin call).

Then, using the specific LogEvent of interest, retrieve individual log messages by calling the scripts logging endpoint again by setting the requestId property of the QueryRequest object.