0

The user is hitting the api and the response will get but we need to handel the responce fields based on the user reqirement in the wso2 APIM.

<sequence xmlns="http://ws.apache.org/ns/synapse" name="Final-using-script">
    <property name="clientUsername" scope="default" expression="$ctx:api.ut.userId"/>
    <log level="custom">
        <property name="userId" expression="$ctx:clientUsername"/>
    </log> 
    <script language="js">
        <![CDATA[
            var payload = mc.getPayloadJSON();
            var log = mc.getServiceLog();        
            log.info(payload);
            var user = mc.getProperty('clientUsername');
            
            if (user === 'abc@carbon.super') {
                delete payload.MobileNo;
                delete payload.EmailID;
                delete payload.SurveyorName;
            } else if (user === 'xyz@carbon.super') {
                delete payload.InsClaimNo;
                delete payload.Acknowledgment;
                delete payload.RejectionMsg;
            }
            
            mc.setPayloadJSON(payload);
        ]]>
    </script>
</sequence>

But i'm getting all the fields from the response it's not getting removed.

I have tried with the payloadFactory mediator also.

The user should get with the minimum fields.

1 Answers1

0

As I understand, you are trying to retriew data based on the user who invokes the API, right? But as per your current approach, you are retrieving all the information and then trying to delete information not relevant to the user.

The more appropriate approach would be use a switch mediator to conditionally identify the user and then make an API or database call to bring on the relevant information.

https://apim.docs.wso2.com/en/latest/integrate/examples/routing_examples/routing_based_on_payloads/

Joy Rathnayake
  • 485
  • 4
  • 8