Manage Transformation
Transformations allow users to do the following operations:
- Perform content modification, injection and removal.
- Accept user-provided JavaScript to alter REST and SOAP messages.
- Change the message exchange protocol from REST to SOAP and vice versa.
How does it work?
Users can define transformation methods for THAPI Manager using the predefined primary object customTransformation. This object includes six pre-defined methods for transforming requests, responses and error objects. THAPI Manager offers six methods for writing code to do transformations.
Following are the four transformation methods used for REST Transformations:
- Request Header.
- Request Body.
- Response Header.
- Response Body.
Following are the two transformation methods used for SOAP Transformations:
- Request SOAP header.
- Response SOAP Header
The above techniques are supported by helper methods which perform the transformation process. To learn more about helper methods, see the sample REST and SOAP Transformation scripts in the subjects listed below.
Following are some of the Header Transformation Methods:
- addRequestHeader(key, value)
This method is used to add headers to a Request.
| Parameter | Parameter Description |
|---|---|
| Key | |
| Value |
- addResponseHeader(key, value)
This method is used to add headers to a Response.
| Parameter | Parameter Description |
|---|---|
| Key | |
| Value |
- getRequestHeaderEntries()
This method retrieves all HTTP headers from the HTTP request during transformation.
| Parameter | Parameter Description |
|---|---|
| Nil | No parameters required |
getRequestHeaderEntries().toString().match('<header name>')
If the header exists, this method returns its name, else it returns null.
| Parameter | Parameter Description |
|---|---|
| Header name | Header name parameter |
REST Transformations
Transformation methods for REST APIs are of two types:
- REST-JSON Transformation
- REST XML Transformation.
REST JSON Transformation
The following transformation methods are used in JSON Transformation for REST APIs:
| Method | Description |
|---|---|
transformRequestHeader() | Use this method to transform HTTP Request Header. |
transformRequestBody() | Use this method to transform Request Body. You can transform Request Body for the following: |
| - Modify existing key or existing value or both | |
| - Add a new JSON element | |
| - Remove a JSON element | |
transformResponseHeader() | Use this method to transform HTTP Response Header. |
transformResponseBody() | Use this method to transform Response Body. You can transform Response Body for the following: |
| - Modify existing key or existing value or both | |
| - Add a new JSON element | |
| - Remove a JSON element |
The following helper transformation methods are used in JSON transformation for REST APIs:
- modifyJsonElement(jsonBody, jsonPath, replaceValue)
This method modifies the value of a JSON element.
| Parameter | Parameter Description |
|---|---|
| jsonBody | Json Body can be obtained using customTransformation.getJsonBody() |
| jsonPath | JsonPath, the path should indicate the Json element whose value is to be modified |
| replaceValue | Indicates the new value to be replaced |
- modifyJsonKeyElement(jsonBody, jsonPath, keyToReplace, replaceKey)
This method modifies the key of a JSON element.
| Parameter | Parameter Description |
|---|---|
| jsonBody | Json Body can be obtained using customTransformation.getJsonBody() |
| jsonPath | JsonPath, the path should indicate the parent key of the key to be modified |
| keyToReplace | Indicates the key to be modified |
| replaceKey | Indicates the new key to be replaced with |
- addJsonElement(jsonBody, jsonPath, addKey, addValue)
This method adds a new Json Element to the Json Body, creating a new key and value pair.
| Parameter | Parameter Description |
|---|---|
| jsonBody | Json Body can be obtained using customTransformation.getJsonBody() |
| jsonPath | JsonPath indicating the key under which the new key-value pair will be added |
| addKey | New key to be added |
| addValue | New value to be added |
- removeJsonElement(jsonBody, jsonPath)
This method is used to remove JSON elements.
| Parameter | Parameter Description |
|---|---|
| jsonBody | Json Body can be obtained using customTransformation.getJsonBody() |
| jsonPath | JsonPath indicating the JSON element to be removed |
Sample JSON Transformation Script
- To add Request Header:
var obj = new Object();
obj.transformRequestHeader = function(customTransformation){
customTransformation.addRequestHeader("CustomTransform","Checking the transformation");
return customTransformation;
}
- To modify/add/remove JSON element from Request Body:
obj.transformRequestBody = function(customTransformation){
//to modify Json element's value
var jsonBody = customTransformation.getJsonBody();
var jsonPath = "$.partyInteraction[0].interactionItem[0].id";
var replaceValue = "555555";
if(jsonBody != "" && jsonPath != "" && replaceValue != ""){
customTransformation.modifyJsonElement(jsonBody, jsonPath, replaceValue);
}
//to modify Json key
var jsonBody = customTransformation.getJsonBody();
var jsonPath = "$..relatedParty[0]";
var keyToReplace = "id";
var replaceKey = "SOA_Id";
if(jsonBody != "" && jsonPath != "" && keyToReplace != "" && replaceKey != ""){
customTransformation.modifyJsonKeyElement(jsonBody, jsonPath, keyToReplace, replaceKey);
}
//to add new Json element
var jsonBody = customTransformation.getJsonBody();
var jsonPath = "$..topic[0]";
var addKey = "New_Key";
var addValue = "New_Value";
if(jsonBody != "" && jsonPath != "" && addKey != "" && addValue != ""){
customTransformation.addJsonElement(jsonBody, jsonPath, addKey, addValue);
}
//to remove Json element
var jsonBody = customTransformation.getJsonBody();
var jsonPath = "$..topic[0].reasonLevel2";
if(jsonBody != "" && jsonPath != ""){
customTransformation.removeJsonElement(jsonBody, jsonPath);
}
return customTransformation;
}
- To add Response Header:
obj.transformResponseHeader = function(customTransformation){
customTransformation.addResponseHeader("Resource","Unknown");
return customTransformation;
}
- To modify/add/remove JSON element from Response Body:
obj.transformResponseBody = function(customTransformation){
//to modify Json element's value
var jsonBody = customTransformation.getJsonBody();
var jsonPath = "$.partyInteraction[0].interactionItem[0].id";
var replaceValue = "555555";
if(jsonBody != "" && jsonPath != "" && replaceValue != ""){
customTransformation.modifyJsonElement(jsonBody, jsonPath, replaceValue);
}
//to modify Json key
var jsonBody = customTransformation.getJsonBody();
var jsonPath = "$..relatedParty[0]";
var keyToReplace = "id";
var replaceKey = "SOA_Id";
if(jsonBody != "" && jsonPath != "" && keyToReplace != "" && replaceKey != ""){
customTransformation.modifyJsonKeyElement(jsonBody, jsonPath, keyToReplace, replaceKey);
}
//to add new Json element
var jsonBody = customTransformation.getJsonBody();
var jsonPath = "$..topic[0]";
var addKey = "New_Key";
var addValue = "New_Value";
if(jsonBody != "" && jsonPath != "" && addKey != "" && addValue != ""){
customTransformation.addJsonElement(jsonBody, jsonPath, addKey, addValue);
}
//to remove Json element
var jsonBody = customTransformation.getJsonBody();
var jsonPath = "$..topic[0].reasonLevel2";
if(jsonBody != "" && jsonPath != ""){
customTransformation.removeJsonElement(jsonBody, jsonPath);
}
return customTransformation;
}
REST XML Transformation
The following are the main XML transformation methods for REST APIs:
| Method | Method Description |
|---|---|
transformRequestHeader() | Use this method to transform HTTP Request Header. |
transformRequestBody() | Use this method to transform XML Request Body. You can transform Request Body for the following: |
| - Modify existing XML node name or node value or both | |
| - Add a new XML element | |
| - Remove an XML element | |
transformResponseHeader() | Use this method to transform HTTP Response Header. |
transformResponseBody() | Use this method to transform XML Response Body. You can transform Response Body for the following: |
| - Modify existing XML node name or node value or both | |
| - Add a new XML element | |
| - Remove an XML element |
The following are the helper methods for XML transformation for REST APIs:
- modifyXmlElement(xmlBody, xPath, NodeToReplace, replaceNodeName, replaceNodeValue, namespace)
This method is used to change an XML element's name, value, or both.
- addXmlElement(xmlBody, parentNode, addNode, addNodeValue)
This method is used to add new XML elements to the XML body (i.e., new nodes).
- removeXmlElement(xmlBody,removeNode)
This method is used to remove an XML element.
| Parameter | Parameter Description |
|---|---|
| xmlBody | XML body obtained from the code using customTransformation.getXmlBody() |
| removeNode | Name of the node which should be removed |
Sample XML Transformation Scripts
- To add Request Header:
obj.transformRequestHeader = function(customTransformation){
customTransformation.addRequestHeader("CustomTransform","Checking the transformation");
return customTransformation;
}
- To modify/add/remove XML element from Request Body:
obj.transformRequestBody = function(customTransformation){
//To modify XML Element without namespace
var xmlBody = customTransformation.getXmlBody();
var xPath = "//FIRSTNAME";
var NodeToReplace = "FIRSTNAME";
var replaceNodeName = "F_NAME";
var replaceNodeValue = "KUSUM";
var namespace = "";
if(xmlBody != "" && xPath != "" && NodeToReplace != ""){
customTransformation.modifyXmlElement(xmlBody, xPath,NodeToReplace, replaceNodeName, replaceNodeValue, namespace);
}
//To modify XML Element with namespace
var xmlBody = customTransformation.getXmlBody();
var xPath = "/bsse:Provision_Network_Response/ns:headerNode";
var NodeToReplace = "ns:headerNode";
var replaceNodeName = "ns:header";
var replaceNodeValue = "2345";
var namespace =
"bsse=http://www.example.com/NetworkProvisioningService/BSS_Request.xsd,ns=http://www.example.com/NetworkProvisioningService/namespaces.xsd";
if(xmlBody != "" && xPath != "" && NodeToReplace != ""){
customTransformation.modifyXmlElement(xmlBody, xPath,NodeToReplace, replaceNodeName, replaceNodeValue,namespace);
}
//To add new Xml Node
var xmlBody = customTransformation.getXmlBody();
var parentNode = "CUSTOMER";
var addNode = "parameterName";
var addNodeValue = "parameterActualValue";
if(xmlBody != "" && parentNode != "" && addNode != "" && addNodeValue != ""){ customTransformation.addXmlElement(xmlBody, parentNode, addNode, addNodeValue);
}
//To remove Xml Node
var xmlBody = customTransformation.getXmlBody();
var removeNode = "CITY";
if(xmlBody != "" && removeNode != ""){
customTransformation.removeXmlElement(xmlBody,removeNode);
}
return customTransformation;
}
- To add Response Header:
obj.transformResponseHeader = function(customTransformation){
customTransformation.addResponseHeader("Resource","Unknown");
return customTransformation;
}
- To modify/add/remove XML element from Response Body:
obj.transformResponseBody = function(customTransformation)
//To modify XML Element
var xmlBody = customTransformation.getXmlBody();
var xPath = "//ns:lastname";
var NodeToReplace = "ns:lastname";
var replaceNodeName = "ns:L_NAME";
var replaceNodeValue = "S";
var namespace = "ns=http://www.example.com/NetworkProvisioningService/nsResponse.xsd"; if(xmlBody != "" && xPath != "" && NodeToReplace != ""){
customTransformation.modifyXmlElement(xmlBody, xPath,NodeToReplace, replaceNodeName, replaceNodeValue, namespace);
}
//To add new Xml Node
var xmlBody = customTransformation.getXmlBody();
var parentNode = "ns:details";
var addNode = "ns:id";
var addNodeValue = "3456";
if(xmlBody != "" && parentNode != "" && addNode != "" && addNodeValue != ""){ customTransformation.addXmlElement(xmlBody, parentNode, addNode, addNodeValue);
}
//To remove Xml Node
var xmlBody = customTransformation.getXmlBody();
var removeNode = "ns:code";
if(xmlBody != "" && removeNode != ""){
customTransformation.removeXmlElement(xmlBody,removeNode);
}
return customTransformation;
SOAP Transformation
The following are the main SOAP transformation methods:
| Method | Description |
|---|---|
| transformRequestHeader() | Use this method to transform HTTP request header. |
| transformSoapRequestHeader() | Use this method to transform SOAP header in request payload. |
| transformSoapResponseHeader() | Use this method to transform SOAP header in response payload. |
| transformRequestBody() | Use this method to transform SOAP body in request payload. |
| transformResponseHeader() | Use this method to transform HTTP response header. |
| transformResponseBody() | Use this method to transform SOAP body in response payload. |
| transformRequestSoapfault() | Use this method to transform gateway fault messages. |
The following are the helper methods used in transforming SOAP APIs:
- addElementToExistingSoapHeader(namespace, namespaceURI, localPart, text)
This method adds SOAP header elements to an existing SOAP header.
| Parameter | Parameter Description |
|---|---|
| namespace | Namespace prefix to be added along with the node name |
| namespaceURI | Namespace URI for the prefix |
| localPart | Indicates the node name |
| text | Indicates the text to be created for the node |
- removeAttributeFromSoapHeader(namespace, element, attribute)
This method is used to remove an attribute from the SOAP header.
| Parameter | Parameter Description |
|---|---|
| namespace | Namespace of the element |
| element | Indicates the node name whose attribute should be removed |
| attribute | Indicates the name of the attribute to be removed |
- removeElementFromExistingSoapHeader(namespace, element)
This method removes SOAP header elements from the existing SOAP header.
| Parameter | Parameter Description |
|---|---|
| namespace | Namespace of the element |
| element | Indicates the node name that should be removed |
- addToHeaderFaultStructure(namespace, namespaceURI, localPart, text)
This method adds the header element to the fault structure.
| Parameter | Parameter Description |
|---|---|
| namespace | Namespace prefix to be added along with the node name |
| namespaceURI | Namespace URI for the prefix |
| localPart | Indicates the node name |
| text | Indicates the text to be created for the node |
- addToDetailFaultStructure(namespace, namespaceURI, localPart, text)
This method is used to include detail elements in the fault structure.
| Parameter | Parameter Description |
|---|---|
| namespace | Namespace prefix to be added along with the node name |
| namespaceURI | Namespace URI for the prefix |
| localPart | Indicates the node name |
| text | Indicates the text to be created for the node |
- addNameSpaceToSoapEnvelope (customTransformation.getSMessage(), namespaceURI, prefix)
This function is used to add an XML namespace URI to the SOAP envelope.
| Parameter | Parameter Description |
|---|---|
| customTransformation.getSMessage() | This function returns the SOAP envelope. |
| namespaceURI | Namespace URI for the prefix. |
| prefix | The prefix to be added to the Namespace URI. |
- addNameSpacePrefixToNode (customTransformation.getSMessage(), namespacePrefix,nodeName,flag)
This method is used to apply the Namespace prefix to a specific node.
| Parameter | Parameter Description |
|---|---|
| customTransformation.getSMessage() | This function returns the SOAP envelope. |
| namespaceURI | Namespace prefix to be added to the node. |
| nodeName | Name of the node for which the prefix has to be added. |
| flag | The flag value can either be true or false. If it is true, the namespace prefix will be added to the specific node and all its child nodes. If it is false, the namespace prefix will be added only for that node. |
The following methods from the list are also used in data recording.
- addElementToExistingSoapHeader(namespace, namespaceURI, localPart, text)
- removeAttributeFromSoapHeader(namespace, element, attribute)
- removeElementFromExistingSoapHeader(namespace, element)
SOAP Sample Transformation Scripts
- Transform SOAP Request Header:
obj.transformSoapRequestHeader = function(customTransformation){
var corNamespace = "cor";
var corNamespaceURI = "";
customTransformation.addElementToExistingSoapHeader(corNamespace, corNamespaceURI, "SOATransactionID", customTransformation.getRequestId());
customTransformation.addElementToExistingSoapHeader(corNamespace, corNamespaceURI, "applicationID", customTransformation.getCNane());
customTransformation.addElementToExistingSoapHeader(corNamespace, corNamespaceURI, "providerID", customTransformation.getOrganization());
customTransformation.addElementToExistingSoapHeader(corNamespace, corNamespaceURI, "originatorIP", customTransformation.getOriginatorIP());
customTransformation.removeAttributeFromSoapHeader("wsse","Security","soapenv:mustUnderstand");
customTransformation.removeAttributeFromSoapHeader("wsse","Security","mustUnderstand");
customTransformation.finalizeTransformation();
return customTransformation;
}
- Transform SOAP Response Header:
obj.transformSoapResponseHeader = function(customTransformation){
if(customTransformation.getSoapHeader()){
customTransformation.removeElementFromExistingSoapHeader("cor", "applicationID");
customTransformation.removeElementFromExistingSoapHeader("cor", "providerID");
customTransformation.removeElementFromExistingSoapHeader("cor", "originatorIP");
customTransformation.removeElementFromExistingSoapHeader("cor", "debugFlag");
customTransformation.finalizeTransformation();
}
return customTransformation;
}
- Transform SOAP fault structure:
obj.transformRequestSoapfault = function(customTransformation){
var corNamespace = "cor";
var corNamespaceURI = "";
customTransformation.addToHeaderFaultStructure(corNamespace, corNamespaceURI, "SOATransactionID", customTransformation.getRequestId());
customTransformation.addToDetailFaultStructure(corNamespace, corNamespaceURI, "SOATransactionID", customTransformation.getRequestId());
customTransformation.addToHeaderFaultStructure(corNamespace, corNamespaceURI, "SOAConsumerTransactionID");
return customTransformation;
}
Protocol Conversion
The following helper methods are used for protocol transformation:
JSON to SOAP Conversion
To convert a JSON body into a SOAP message, use the following technique.
- jsonToSoap(JsonObject jsonbody, String soapProtocol, String soapAction)
| Parameter | Description |
|---|---|
| jsonbody | This can be obtained using customTransformation.getJsonBody() |
| SoapProtocol | This can be obtained using customTransformation.getJsonBody() |
| soapAction | This can be obtained using customTransformation.getJsonBody() |
To get the incoming JSON request body, use the following code:
var jsonBody = customTransformation.getJsonBody();
To set up the SOAP protocol, enter the following code:
- SOAP protocol can either be SOAP_PROTOCOL_1_1 or SOAP_PROTOCOL_1_2.
- Based on your requirements, you can change the SOAP protocol.
var soapProtocol = "SOAP_PROTOCOL_1_1";
To pass the soapAction attribute, use the code below. If the attribute is not available, you can Pass an empty string instead.
var soapAction = "";
To convert JSON to SOAP, use the following code.
customTransformation.jsonToSoap(jsonBody, soapProtocol, soapAction);
Sample Transformation script:
var obj = new Object();
obj.transformRequestHeader = function(customTransformation){
customTransformation.addRequestHeader("CustomTransform","Checking the transformation");
return customTransformation;
}
obj.transformRequestBody = function(customTransformation){
var transformedReqBody;
var jsonBody = customTransformation.getJsonBody();
var soapProtocol = "SOAP_PROTOCOL_1_1";
var soapAction = "http://webservice.ws.jax.learn.com/";
if(jsonBody != "" && soapProtocol != ""){
transformedReqBody = customTransformation.jsonToSoap(jsonBody, soapProtocol, soapAction);
}
customTransformation.addNamespaceToXml(customTransformation.getSMessage(),"RESULT_STATUS","http://www.<example.com>/NetworkProvisioningService/Request.xsd","bsse"); customTransformation.addNamespaceToXml(customTransformation.getSMessage(),"BSOID","http://<example>.ie/coredata_1_0","cor");
return customTransformation;
}
obj.transformResponseHeader = function(customTransformation){
customTransformation.addResponseHeader("Resource","Header");
return customTransformation;
}
obj.transformResponseBody = function(customTransformation){
var jsonResponse;
var soapMessage = customTransformation.getSMessage();
if(soapMessage != ""){
jsonResponse = customTransformation.soapToJson(soapMessage);
}
return customTransformation;
}
- soapToJson(String soapMessage)
This method is used to convert SOAP messages into JSON.
| Parameter | Description |
|---|---|
| soapMessage | This can be obtained using customTransformation.getSMessage() |
Sample Transformation script:
var obj = new Object();
obj.transformRequestHeader = function(customTransformation){
customTransformation.addRequestHeader("CustomTransform","Checking the transformation");
return customTransformation;
}
obj.transformRequestBody = function(customTransformation){
var soapMessage = customTransformation.getSMessage();
if(soapMessage != ""){
customTransformation.soapToJson(soapMessage);
}
return customTransformation;
}
obj.transformResponseHeader = function(customTransformation){
customTransformation.addResponseHeader("Resource","Header");
return customTransformation;
}
obj.transformResponseBody = function(customTransformation){
var soapResponse;
var jsonBody = customTransformation.getJsonBody();
var soapProtocol = "SOAP_PROTOCOL_1_1";
var soapAction = null;
if(jsonBody != "" && soapProtocol != ""){
soapResponse = customTransformation.jsonToSoap(jsonBody, soapProtocol, soapAction);
}
return customTransformation;
}
- xmlToSoap(String xml, String soapProtocol, String soapAction)
This method is used to convert XML to SOAP messages.
| Parameter | Description |
|---|---|
| xml | This can be obtained by using customTransformation.getXmlBody() |
| soapProtocol | |
| soapAction |
Sample Transformation script:
var obj = new Object();
obj.transformRequestHeader = function(customTransformation){
customTransformation.addRequestHeader("CustomTransform","Checking the transformation");
return customTransformation;
}
obj.transformRequestBody = function(customTransformation){
var transformedReqBody;
var xmlBody = customTransformation.getXmlBody();
var soapProtocol = "SOAP_PROTOCOL_1_1";
var soapAction = "http://webservice.ws.jax.learn.com/";
if(xmlBody != "" && soapProtocol != ""){
transformedReqBody = customTransformation.xmlToSoap(xmlBody, soapProtocol, soapAction);
}
customTransformation.addNamespaceToXml(customTransformation.getSMessage(),"RESULT_STATUS","http://www.<example.com>/NetworkProvisioningService/Request.xsd","bsse");
customTransformation.addNamespaceToXml(customTransformation.getSMessage(),"BSOID","http://<example>.o2.ie/coredata_1_0","cor");
return customTransformation;
}
obj.transformResponseHeader = function(customTransformation){
customTransformation.addResponseHeader("Resource","Header");
return customTransformation;
}
obj.transformResponseBody = function(customTransformation){
var xmlResponse;
var soapMessage = customTransformation.getSMessage();
if(soapMessage != ""){
xmlResponse = customTransformation.soapToXml(soapMessage);
}
return customTransformation;
}
- soapToXml(String soapMessage)
This method can be used to convert a SOAP message into XML.
| Parameter | Description |
|---|---|
| soapMessage | This can be obtained using customTransformation.getSMessage() |
Sample Transformation script:
var obj = new Object();
obj.transformRequestHeader = function(customTransformation){
customTransformation.addRequestHeader("CustomTransform","Checking the transformation");
return customTransformation;
}
obj.transformRequestBody = function(customTransformation){
var soapMessage = customTransformation.getSMessage();
if(soapMessage != ""){
customTransformation.soapToXml(soapMessage);
}
return customTransformation;
}
obj.transformResponseHeader = function(customTransformation){
customTransformation.addResponseHeader("Resource","Header");
return customTransformation;
}
obj.transformResponseBody = function(customTransformation){
var soapResponse;
var xmlBody = customTransformation.getXmlBody();
var soapProtocol = "SOAP_PROTOCOL_1_1";
var soapAction = null;
if(xmlBody != "" && soapProtocol != ""){
soapResponse = customTransformation.xmlToSoap(jsonBody, soapProtocol, soapAction);
}
return customTransformation;
}
- addNamespaceToXml(String xml, String nodeName, String namespaceURI, String prefix)
This method can be used to add Namespace URI and prefixes in the XML body.
| Parameter | Description |
|---|---|
| xml | This can be obtained by using customTransformation.getXmlBody() |
| nodeName | Name of the node for which prefix should be added |
| namespaceURI | Namespace URI |
| prefix | Prefix to append to the node |
Encryption and Decryption
The Helper Transformation Methods for Encryption and Decryption are as follows:
- encryptDecryptHeader(String headerKey, String mode, String algorithm)
This method is used to encrypt and decrypt header values. This approach can be applied to both request and response headers.
| Parameter | Parameter Description |
|---|---|
| headerKey | Name of the header whose value is to be encrypted or decrypted |
| mode | Mode of transformation. Use Encryption to encrypt and Decryption to decrypt |
| algorithm | Name of the algorithm using which encryption or decryption will take place.Use Base64 for base 64 encryption and RSA for RSA encryption |
- encryptDecryptPayload(String payload, String mode, String algorithm, String path, String payloadType, String namespace)
This function encrypts or decrypts any element in request or response payload.
| Parameter | Parameter Description |
|---|---|
| payload | Pass the JSON/REST XML/SOAP XML payload for transformation. Use customTransformation.getJsonBody() to get JSON payload, Use customTransformation.getXmlBody() to get REST XML payload, Use customTransformation.getSMessage() to get SOAP XML payload |
| mode | Mode of transformation. Use Encryption to encrypt and Decryption to decrypt |
| algorithm | Name of the algorithm using which encryption or decryption will take place. Use Base64 for base 64 encryption and RSA for RSA encryption |
| path | Path of the element to be transformed. Use Xpath for REST and SOAP XML payloads and JsonPath for JSON payloads |
| payloadType | Indicates the type of the payload. Use REST-XML for REST XML payloads, Use SOAP-XML for SOAP XML payloads, Use JSON for JSON payloads |
| namespace | The namespaceURI if the xpath contains namespace prefix. If there is no namespace prefix in the xpath, then this field can be empty or null. If the xpath contains multiple namespace prefixes, then comma-separated namespaceURI should be given. The format for this field is: namespace = prefix1=namespaceUri1,prefix2=namespaceUri2. |
Sample Encryption/Decryption Transformation Script
- To encrypt Request header
obj.transformRequestHeader = function(customTransformation){
customTransformation.encryptDecryptHeader("userId", "Encryption", "Base64");
return customTransformation;
}
- To decrypt Response header
obj.transformResponseHeader = function(customTransformation){
customTransformation.encryptDecryptHeader("accountId", "Decryption", "Base64");
return customTransformation;
}
- To encrypt JSON Request payload
obj.transformRequestBody = function(customTransformation){
var json = customTransformation.getJsonBody();
var jsonPath = "$..donor.accountId";
if(json != "" && jsonPath != ""){
customTransformation.encryptDecryptPayload(json, "Encryption", "Base64", jsonPath, "JSON", "");
}
return customTransformation;
}
- To encrypt SOAP XML Request payload
obj.transformRequestBody = function(customTransformation){
var soap = customTransformation.getSMessage();
var xpath = "//tem:intA";
var namespace = "tem=http://tempuri.org/";
if(soap != "" && xpath != ""){
customTransformation.encryptDecryptPayload(soap, "Encryption", "Base64", xpath, "SOAP-XML", namespace);
}
return customTransformation;
}
- To decrypt JSON Response payload
obj.transformResponseBody = function(customTransformation){
var json = customTransformation.getJsonBody();
var jsonPath = "$..SOATransactionID";
if(json != "" && jsonPath != ""){
customTransformation.encryptDecryptPayload(json, "Decryption", "Base64", jsonPath, "JSON", "");
}
return customTransformation;
}
Payload Conversion
Payload conversion is the transformation of data format from one representation to another, facilitating interoperability between systems with different data formats.
XML to JSON:
XML to JSON is the process of converting data encoded in XML format into JSON format. This conversion allows for interoperability between systems or applications that use different data representation standards, enabling communication and data exchange between them.
JSON to XML
JSON to XML enables the conversion of data payloads from JSON format to XML format for compatibility between systems.
None:
No conversion occurs when both the client application backend and receiving application support JSON services, resulting in the value "None" for JSON requests and responses.
The transformation will apply in accordance with the transformation script even while payload conversion does not occur.
Include a Transformation
Transformations can only be added to an API while it is in the Draft state.
- Navigate to the API's Transformation tab.
The Screen appears as shown below.

-
Users can add transformation scripts for individual resources at the resource level.
-
Users can add transformation scripts for the entire API at the API level.
There are two ways to add a transformation script at the resource level.
- Script
- Custom
Include a Transformation at the resource/operation level (Script)
If REST API is selected, the resource level is displayed. If SOAP API is selected, the operation level is displayed.
- Ensure that Resource/Operation Level is selected.

-
Enable the appropriate toggle to allow editing.
-
Select Payload Converter from the drop down based on your requirements.
-
Click Script.
Resource/Operation - Transformation Script dialog box appears as shown below.
If REST API is selected, the resource level is displayed. If SOAP API is selected, the operation level is displayed.
- Enter the Script and click Submit.
On submitting, the confirmation message appears as shown below.

Include a Transformation at the resource/Operation level (Custom)
If REST API is selected, the resource level is displayed. If SOAP API is selected, the operation level is displayed.
- Ensure that Resources/Operation Level is selected.

-
Enable the appropriate toggle to allow editing.
-
Select Payload Converter from the drop down based on your requirements.
-
Click Custom.
The screen appears as shown below.

-
Choose the format and update the place holder under the request types based on your requirements.
-
Click Submit.
On submitting, the confirmation message appears as shown below.

Include a Transformation at the API level (Script)
- Click the API Level tab.

-
Ensure that Script tab is selected.
-
Enter the Script and click Submit.
On submitting, the confirmation message appears as shown below.

Include a Transformation at the API level (Custom)
- Click the API Level tab.

-
Click the Custom sub tab.
-
Choose the format and update the place holder under the request types based on your requirements.
-
Click Submit.
On submitting, the confirmation message appears as shown below.
