GatewayScript

Use the gatewayscript policy to execute a specified DataPower® GatewayScript program.

Gateway support

Table 1. Table showing which gateways support this policy, and the corresponding policy version
Gateway Policy version
DataPower Gateway (v5 compatible) 1.0.0
DataPower API Gateway, policy available from V2018.4.1.0 2.0.0

This topic describes how to configure the policy in the assembly user interface; for details on how to configure the policy in your OpenAPI source, see gatewayscript.

About

You can attach this policy to the following API flows:
  • REST
  • SOAP

The gatewayscript policy gives you built-in access to the DataPower Gateway module via variable apim.

Properties

The following table lists the policy properties, indicates whether a property is required, specifies the valid and default values for input, and specifies the data type of the values.

Table 2. gatewayscript policy properties
Property label Required Description Data type
Title No The title of the policy.

The default value is gatewayscript.

string
Description No A description of the policy. string
Source Yes The GatewayScript source code to execute. For example:
var message = [ 'Hello', 'World!' ];
console.debug(message.join(' '));
string

Examples

The following examples show how the full OpenAPI for the policy looks in the source code.

Example one:
gatewayscript:
  title: writes message to DataPower log
  source: console.debug('Hello World!');
Example two:
gatewayscript:
  title: script written in multiple lines
  source: |
    var message = [ 'Hello', 'World!' ];
    console.debug(message.join(' '));

For more code examples, see GatewayScript code examples and, if you are using the DataPower API Gateway, Using context variables in GatewayScript and XSLT policies with the DataPower API Gateway.

For general information on using GatewayScript, see the following topics in the DataPower product documentation:

Errors

The following error can be thrown while the policy is being executed:
  • JavaScriptError - a generic error that captures all errors that occur during the execution of the policy.