Hi There,
using extract variable I've extracted a string how would i compare it?
Below is the sample i want to compare to check the received XML element containing the region texas, Atlanta and Ontario if it doesn't one of that wanted to reject. Pls advice.
/ScreeningRequest/region
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="EV.ExtractScreeningRequestParams"> <DisplayName>EV.ExtractScreeningRequestParams</DisplayName> <Properties/> <XMLPayload> <Namespaces/> <Variable name="region" type="string"> <XPath>/ScreeningRequest/region</XPath> </Variable> <Variable name="serviceInvokerName" type="string"> <XPath>/ScreeningRequest/serviceInvokerName</XPath> </Variable> <Variable name="screeningRequestData" type="nodeset"> <XPath>/ScreeningRequest/screeningRequestData</XPath> </Variable> </XMLPayload> <Source clearPayload="false">request</Source> </ExtractVariables>
Solved! Go to Solution.
Hi, you can to do that using JavaScript policy. https://docs.apigee.com/api-platform/reference/policies/javascript-policy
You can retrieve the response payload, and use search javascript function to find within all payload the data. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search
After your search, you can define a value for a variable that is used by Error policy. It will stop the flow and show an error if you want.
You can use various approaches.
option 1: ExtractVariables will extract that value into a variable. Subsequent to that policy, you can use a Condition element in your proxy flow to compare. Check the documentation on Conditions for examples.
option 2: there is a Regular Expression Protection policy . You can specify the XPath and a regular expression, like (Texas|Ontario|Atlanta), to match. In this case you don't need ExtractVariables.
option 3: you could write a JAvaScript custom policy to compare your extracted value with the acceptable values.
Hi, you can to do that using JavaScript policy. https://docs.apigee.com/api-platform/reference/policies/javascript-policy
You can retrieve the response payload, and use search javascript function to find within all payload the data. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search
After your search, you can define a value for a variable that is used by Error policy. It will stop the flow and show an error if you want.
You can use various approaches.
option 1: ExtractVariables will extract that value into a variable. Subsequent to that policy, you can use a Condition element in your proxy flow to compare. Check the documentation on Conditions for examples.
option 2: there is a Regular Expression Protection policy . You can specify the XPath and a regular expression, like (Texas|Ontario|Atlanta), to match. In this case you don't need ExtractVariables.
option 3: you could write a JAvaScript custom policy to compare your extracted value with the acceptable values.