Search code examples
apigee

conditionals and flow control on payload


I have some variables that will affect my responses on a payload but it requires an if. is there a way to add conditionals or flow control on the payload to display or not a section according to the value of a variable?

thanks for any guidance

Marco


Solution

  • You should be able to do this with a combination of Extract Variables and JavaScript callouts. With the Extract Variables policy, you would extract the body of the request or response. Then, with the JavaScript callout, you would do any logic based on the contents of the body. E.g.:

    var myvar = context.getVariable("<variable>.body");
    
    myvar = <whatever manipulation you want to do here>;
    
    context.setVariable("<variable>.body", myvar);