Conditional expression with variable - troubleshooting

Hi,

I am trying to prove that you can use Apigee Edge to return different values based on a condition. In this case the condition is a variable pulled from a response in JSON.

My conditions are not working. As far as I can tell from the Trace the jsonpath expression is working, and my variable is being identified correctly. (In this example there are two options - 'CA' or 'TX').

My understanding is that if the condition is satisfied then the step will execute. I would like to return a different statement depending on the value of of the variable. Note that the response here is a standin for a proper route, but I will fill the route in later. For now I just want to prove that it works.

Probably I am missing something obvious, so any help is much appreciated.

Here is my flow:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response>
            <Step>
                <Name>Extract-Variables-1</Name>
            </Step>
            <Step>
                <Name>Assign-Message-CA</Name>
                <Condition>(state = "CA")</Condition>
            </Step>
            <Step>
                <Name>Assign-Message-TX</Name>
                <Condition>(state = "TX")</Condition>
            </Step>
        </Response>
    </PostFlow>
    <Flows/>
    <HTTPProxyConnection>
        <BasePath>/pid_apigee_pep</BasePath>
        <Properties/>
        <VirtualHost>default</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>
<br />

And the extract variables code, for reference:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
    <DisplayName>Extract Variable - State</DisplayName>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="state">
            <JSONPath>$.response[0].access[0].attributes.state[0]</JSONPath>
        </Variable>
    </JSONPayload>
    <Source clearPayload="false">response</Source>
</ExtractVariables>
0 7 671
7 REPLIES 7

What response are you seeing when you make a call?

Will you be able to share your trace?

Thanks for reminding me - I should have included this with the original question.

The response is just the json message from my backend, because the conditional expressions are not taking effect.

I tried to attach the trace but the file was rejected because it was xml. Here it is as a txt file, just change the extension back to xml. trace-1561751832828.txt

And here is the json response with the fictional data:

response.txt

If you notice your trace there are two variables named state (one in-built system variable and the other from extract variable), may be that's the cause of the condition not satisfied.

You can try using a different variable name or adding a variable prefix like backendresponse and referring to backendresponse.state in the condition and check

8755-trace.png

Your solution worked! Thanks for that.

Changed the variable to something not named 'state' and it worked as expected.

I saw the two 'state' variables in the trace but figured that was just how apigee handled them; it did not occur to me that there would be a 'state' system variable, although it should have. Leave it to me to choose a variable that already existed.

Thanks again for your your help.

Glad it worked!