Reputation: 27
I have taken the request payload from the frontend in the wso2 apim custom sequence using the below property.
<property name="RequestPayload" expression="json-eval($)" />
Let the request payload be
{
"token": "jhghjgjhghjg",
"parameters": {
"Name": "alice",
"appName": "app",
"Id": "Id"
},
"date": {
"min": "this.startOrMin",
"max": "this.endOrMax",
"formats": [
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd HH:mm:ss"
]
},
"limit": "this.apiService.noOfRecords"
}
Consider I want to remove the Id field in the request payload before sending to the backend.
I have used a java class mediator in the sequence where I process this request payload taken from the property.
String ReqPayload = synapsecontext.getProperty("RequestPayload").toString();
log.info("ReqPayload: " + ReqPayload);
Suggest a way to modify/remove the payload field either in the class mediator or in the custom sequence before sending to the backend.
Upvotes: 0
Views: 759
Reputation: 1330
The easiest way for your payload is to use script mediator, like below:
<script language="js"><![CDATA[
var message = mc.getPayloadJSON();
delete message.parameters.Id;
mc.setPayloadJSON(message);
]]></script>
It is safe, if the parameters.Id
doesn't exist in payload, but be aware, thatparameters
should exist. If not, you must check it before trying remove parameters.Id
.
Upvotes: 1