Manage Data Recording
The TH API Manager allows users to create scripts based on templates to log data for each resource/operation. The script can manipulate requests and responses, including payloads and header information, by adding, removing, or hiding specific data.
Refer to the table at the conclusion of this subject for more information on data recording methods.
Data Recording Methods
The following are the masking methods used in data recording.
| Method | Description |
|---|---|
| maskJsonRequestBody() | Mask JSON request body |
| maskJsonResponseBody() | Mask JSON response body |
| maskRestXmlRequestBody() | Mask REST XML request body |
| maskRestXmlResponseBody() | Mask REST XML response body |
| maskRequestBody() | Mask SOAP request body |
| maskResponseBody() | Mask SOAP response body |
Helper Methods Used
- modifyElementUsingJsonPath(jsonBody, jsonPath, replaceText).
This method is used to mask the JSON body.
| Parameter | Description |
|---|---|
| jsonBody | JSON Body obtained from the code |
| jsonPath | JsonPath indicating the key whose value should be masked |
| replaceText | The replace value used to mask |
- partialMaskingUsingJsonPath(jsonBody, jsonPath, startLen, endLen, maskUnmask).
This method is used to partially mask JSON data.
| Parameter | Description |
|---|---|
| jsonBody | JSON Body can be obtained from the code using transactionRecording.getXmlBody() |
| jsonPath | JsonPath indicating the key whose value should be masked |
| startLen | Number of starting characters in the jsonPath value to be masked/unmasked |
| endLen | Number of last characters in the jsonPath value to be masked/unmasked |
| maskUnmask | Indicates whether to mask or unmask the number of characters specified in the above two parameters |
- modifyElementUsingXPath(xmlBody, xpath, replaceText,namespace).
This method is used to mask the REST XML and SOAP body.
| Parameter | Description |
|---|---|
| xmlBody | xmlBody can be obtained from the code |
| xpath | XPath indicating the key whose value should be masked |
| replaceText | The replace value used to mask |
| 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 |
If no replace text is provided, the value in the x-path will be replaced with The number of stars will based on the length of the value.
- partialMaskingUsingXPath(xmlBody, xpath, namespace, startLen, endLen, maskUnmask).
This method is used to mask REST XML and SOAP XML data partially.
| Parameter | Description |
|---|---|
| xmlBody | xmlBody can be obtained from the code using transactionRecording.getXmlBody() |
| xpath | The path should indicate the key whose value should be masked |
| 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 |
| startLen | No. of starting characters in the XPath value to be masked/unmasked |
| endLen | No. of last characters in the XPath value to be masked/unmasked |
| maskUnmask | Indicates whether to mask or unmask the no. of characters specified in the above two parameters |
-
If the value of the parameter maskUnmask is mask, the characters indicated by startLen and endLen will be masked with *, while the other characters in the value will be unmasked.
-
If the parameter maskUnmask is set to unMask, the characters given by startLen and endLen will be unmasked, while the remaining characters will be masked with *.
Additionally, the following helper methods can be used for masking in data recording:
| Method name | Method Description | Parameter | Parameter Description |
|---|---|---|---|
| modifyElementUsingJsonPath(jsonBody, jsonPath, replaceText) | This method is used to mask JSON body. | jsonBody | Json Body can be obtained from the code. |
| jsonPath | The path should indicate the key whose value should be masked. | ||
| replaceText | The replace value used to mask. | ||
| modifyElementUsingXPath(xmlBody, xpath, replaceText) | This method is used to mask REST XML body and SOAP body. | xmlBody | xmlBody can be obtained from the code. |
| xpath | The path should indicate the key whose value should be masked. | ||
| replaceText | The replace value used to mask. |
If the xpath contains a namespace prefix, add the relevant namespaceURI to the gateway.properties file.
To add a namespace URI in the gateway.properties file, use the syntax prefix=namespaceURI.
Data Recording Sample Scripts
var obj = new Object();
//to mask json request body
obj.maskJsonRequestBody = function(transactionRecording){
var maskedJsonBody;
var jsonBody = transactionRecording.getXmlBody();
var jsonPath = "$..BSOID";
var replaceText = "XXXXXXXXXX";
if(jsonBody != "" && jsonPath != ""){
maskedJsonBody = transactionRecording.modifyElementUsingJsonPath(jsonBody, jsonPath, replaceText);
transactionRecording.setXmlBody(maskedJsonBody);
}
return transactionRecording;
}
//to mask json response body
obj.maskJsonResponseBody = function(transactionRecording){
var maskedJsonBody;
var jsonBody = transactionRecording.getXmlBody();
var jsonPath = "$..ERROR_CODE";
var replaceText = "XXXXXXXXXX";
if(jsonBody != "" && jsonPath != ""){
maskedJsonBody = transactionRecording.modifyElementUsingJsonPath(jsonBody, jsonPath, replaceText);
transactionRecording.setXmlBody(maskedJsonBody);
}
return transactionRecording;
}
//to mask soap request body
obj.maskRequestBody = function(transactionRecording){
var maskedxmlBody;
var xmlBody = transactionRecording.getXmlBody();
var xpath = "//bss:Provision_Network_Response";
var replaceText = "XXXXXXXXXX";
if(xmlBody != "" && xpath != ""){
maskedxmlBody = transactionRecording.modifyElementUsingXPath(xmlBody, xpath, replaceText);
transactionRecording.setXmlBody(maskedxmlBody);
}
return transactionRecording;
}
//to mask soap response body
obj.maskResponseBody = function(transactionRecording){
var maskedxmlBody;
var xmlBody = transactionRecording.getXmlBody();
var xpath = "//bss:ERROR_CODE";
var replaceText = "XXXXXXXXXX";
if(xmlBody != "" && xpath != ""){
maskedxmlBody = transactionRecording.modifyElementUsingXPath(xmlBody, xpath, replaceText);
transactionRecording.setXmlBody(maskedxmlBody);
}
return transactionRecording;
}
//to mask rest xml request body
obj.maskRestXmlRequestBody = function(transactionRecording){
var maskedxmlBody;
var xmlBody = transactionRecording.getXmlBody();
var xpath = "//bsse:STATUS_CODE";
var replaceText = "XXXXXXXXXX";
if(xmlBody != "" && xpath != ""){
maskedxmlBody = transactionRecording.modifyElementUsingXPath(xmlBody, xpath, replaceText);
transactionRecording.setXmlBody(maskedxmlBody);
}
return transactionRecording;
}
//to mask rest xml response body
obj.maskRestXmlResponseBody = function(transactionRecording){
var maskedxmlBody;
var xmlBody = transactionRecording.getXmlBody();
var xpath = "//bsse:RESULT_STATUS";
var replaceText = "XXXXXXXXXX";
if(xmlBody != "" && xpath != ""){
maskedxmlBody = transactionRecording.modifyElementUsingXPath(xmlBody, xpath, replaceText);
transactionRecording.setXmlBody(maskedxmlBody);
}
return transactionRecording;
}
Add Data Recording
If REST API is selected, the resource name is displayed. If SOAP API is selected, the operation name is displayed.
- Navigate to the REST/SOAP API's Data Recording tab.
The Screen appears as shown below.

- Click Add Script.
Resource/Operation Level - Data Recording Script dialog box appears as shown below.
-
Enter the Script.
-
Click Submit.
The application transfers you to the Data Recording screen.
- Click Save as Draft.

On saving, the confirmation message appears as shown below.
