General Information
Policy Type
Description
Script policy allows you to execute custom scripts (Groovy or JavaScript) during request/response processing. Scripts can modify requests, responses, set variables, call external services, and perform custom business logic.Endpoints
List Policies
Add Policy
Update Policy
Delete Policy
List Policies
Endpoint
Request
Headers
| Header | Value |
|---|---|
| Authorization | Bearer {token} |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| projectName | string | Yes | Project name |
| apiProxyName | string | Yes | API Proxy name |
Response
Success Response (200 OK)
cURL Example
Add Policy
Endpoint
Request
Headers
| Header | Value |
|---|---|
| Authorization | Bearer {token} |
| Content-Type | application/json |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| projectName | string | Yes | Project name |
| apiProxyName | string | Yes | API Proxy name |
| policyName | string | Yes | Policy name |
Request Body
Full JSON Body Example
Request Body Fields
operationMetadata
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| targetScope | string | Yes | - | Policy scope: ALL or ENDPOINT |
| targetEndpoint | string | No* | - | Endpoint path (required if targetScope=ENDPOINT) |
| targetEndpointHTTPMethod | string | No* | - | HTTP method (required if targetScope=ENDPOINT) |
| targetPipeline | string | Yes | - | Pipeline: REQUEST, RESPONSE, or ERROR |
| deploy | boolean | No | true | Whether to deploy after adding policy |
| deployTargetEnvironmentNameList | array | No | [] | List of environment names to deploy to |
| order | integer | No | null | Policy execution order (starts from 1) |
ALL- Policy applies to all endpointsENDPOINT- Policy applies only to specified endpoint
REQUEST- Executes in request pipelineRESPONSE- Executes in response pipelineERROR- Executes in error pipeline
GET,POST,PUT,DELETE,PATCH,OPTIONS,HEAD
policy
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| type | string | Yes | - | Policy type: policy-script |
| description | string | No | - | Policy description |
| active | boolean | No | true | Whether policy is active |
| executionType | string | Yes | - | Execution type: SYNC or ASYNC |
| scriptLanguage | string | Yes | - | Script language: GROOVY or JAVASCRIPT |
| scriptBody | string | Yes | - | Script code to execute |
EnumExecutionType (executionType)
SYNC- Synchronous execution (blocks request/response until script completes)ASYNC- Asynchronous execution (non-blocking, script runs in background)
EnumScriptType (scriptLanguage)
GROOVY- Groovy scripting languageJAVASCRIPT- JavaScript (Nashorn engine)
Script Context Variables
The script has access to the following variables:messageContext- Message context object (request/response)request- HTTP request object (available in REQUEST pipeline)response- HTTP response object (available in RESPONSE/ERROR pipeline)variables- Variable map for storing/retrieving valueslogger- Logger for script logging
Response
Success Response (200 OK)
cURL Example
Update Policy
Endpoint
Request
Headers
| Header | Value |
|---|---|
| Authorization | Bearer {token} |
| Content-Type | application/json |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| projectName | string | Yes | Project name |
| apiProxyName | string | Yes | API Proxy name |
| policyName | string | Yes | Policy name |
Request Body
Full JSON Body Example
Response
Success Response (200 OK)
cURL Example
Delete Policy
Endpoint
Request
Headers
| Header | Value |
|---|---|
| Authorization | Bearer {token} |
| Content-Type | application/json |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| projectName | string | Yes | Project name |
| apiProxyName | string | Yes | API Proxy name |
| policyName | string | Yes | Policy name |
Request Body
Full JSON Body Example
Request Body Fields
operationMetadata
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| targetScope | string | Yes | - | Policy scope: ALL or ENDPOINT |
| targetPipeline | string | Yes | - | Pipeline: REQUEST, RESPONSE, or ERROR |
| deploy | boolean | No | false | Whether to deploy after deletion |
Response
Success Response (200 OK)
cURL Example
Notes and Warnings
-
Script Execution:
SYNC- Script executes synchronously and blocks request/response processingASYNC- Script executes asynchronously and does not block processing
-
Script Languages:
GROOVY- Full Groovy support with access to Java APIsJAVASCRIPT- JavaScript (Nashorn engine) with limited Java API access
-
Script Context: Scripts have access to:
messageContext- Message context (request/response)request- HTTP request object (REQUEST pipeline)response- HTTP response object (RESPONSE/ERROR pipeline)variables- Variable map for data storagelogger- Logger for script logging
-
Performance:
- Synchronous scripts block request/response processing
- Keep scripts simple and fast for better performance
- Use asynchronous scripts for non-critical operations
- Error Handling: Script errors can break request/response processing. Test scripts thoroughly.
- Security: Scripts have full access to request/response data. Validate and sanitize inputs.
-
Deployment: Policy changes require deployment to take effect. Set
deploy: trueor deploy manually.
Related Documentation
- List Policies - List all policies
- Add Policy - General policy addition guide
- Update Policy - General policy update guide
- Delete Policy - General policy deletion guide

