Script Call Out
The Script Call Out policy enables addition of custom JavaScript codes and Python codes that execute within the context of an API proxy flow.
This policy allows the addition or replacement/modification of the Payload and Context Variables. This policy can manage the function of Assign Variables, allowing configuration of multiple context variables in the script.
Example
A basic script is provided for javascript and python in the API UI itself (as seen in the figure above), which acts as a template. Below are sample scripts available in the Script editor section.
JavaScript
// function definition
function myFunction() {
message.payload = '<Modified Payload >';
message.contextVariable.'<context variable name>' = '<value of modified context variable>';
}
// function invocation
myFunction();
Python
def myFunction():
if(message.has_key('payload')):
message['payload'] ='<modified payload >'
if(message['contextVariable'].has_key('<context variable name>')):
message['contextVariable']['<context variable name>'] = '<Value of context variable>'
return message;