How can I read Condition Expression using JS or policies?

Not applicable

Hi Apigee Community,

I have a question about conditions, used in conditional flows. Assuming that I have a condition like that:

<Condition>(proxy.pathsuffix MatchesPath "/a/b**") and (request.verb = "GET")</Condition>

and in proxy trace I can see:

Properties:

ExpressionResult true
Expression	(proxy.pathsuffix matches /a/b/** and (request.verb equals "GET"))
Tree		conditional-flow-name_REQUEST_FLOW

Is it possible to somehow read property Expression using Javascript (or any other policy)?

Solved Solved
2 6 1,807
1 ACCEPTED SOLUTION

Not applicable

Well, I am quite sure if we read the expression, but we can read the flow name (context variable "current.flow.name") for sure. And there is typically an 1-1 connection between the expression and the flow name. And then you can create a single JS file with all the possible conditions with the flow name.

View solution in original post

6 REPLIES 6

Not applicable

Hello @Jarosław Wojtalik,

If you asking if you can read those parameters in the js file, then the answer is yes. The values are available at "proxy.pathsuffix" and "request.verb".

So, you can do a context.getVariable() operation on these 2 variables to use them in the Javascript.

But you have to write your own appropriate condition in the js file to make it work. Specially, you would not find any "MatchesPath" equivalent one in the js file oob.

Here is an sample, to check if the uri path contains "channel" in the request (equivalent to MatchesPath /channel in proxy condition):

var proxySuffix = context.getVariable("proxy.pathsuffix");

if (proxySuffix.match(/channel/g))
	context.setVariable("allowMethod","POST,DELETE");

Hello @MEGHDEEP BASU,

I know that I can read variables like: "proxy.pathsuffix", but my main question is if I can read somehow in javascript condition expression, with something like:

context.getVariable("Expression");

I want to do this in order to avoid typing too many values in js like:

/channel/g

In order to obtain "channel" part (or different ones from other conditions), I would like to parse them from condition expression, so I can re-use my JS in different places.

This would also help me in case condition changes, I would not have to update javascript with new string values.

Not applicable

Adding Apigee people with whom we had previous discussions about configuring API proxies:

@mchalmers @Srinivas Sudhindra @Yuriy @NICOLA CARDACE

Adding TomTom watchers:

@Emilia Ipate

Not applicable

Well, I am quite sure if we read the expression, but we can read the flow name (context variable "current.flow.name") for sure. And there is typically an 1-1 connection between the expression and the flow name. And then you can create a single JS file with all the possible conditions with the flow name.

Hi @MEGHDEEP BASU,

thank you for your answer and different idea on how to approach the problem. I like what you proposed and I think it is a quite good answer to my question.

Regards,

Jarosław

Hello @Meghdeep Basu

Regarding your previous reply, I can read the value of "current.flow.name" but I'm attempting to create something more dynamic and I need to read the value of Properties Expression (Eg: Expression(proxy.pathsuffix matches /a/b/** and (request.verb equals "GET")) as posted by @Jarosław Wojtalik. Can you please advise how i'm able to do so? (Inside javascript policy would be preferable)

Thanks in advance.