Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to raise a fault on missing or empty request param,How to raise a fault if a query parameter is missing or empty

Hi,

I have an endpoint which needs an 'email' parameter and if the email parameter is missing or empty it need to raise a fault.

I have this code but, it doesn't work.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>Verify-API-Key-1</Name>
            </Step>
            <Step>
                <Name>remove-query-param-apikey</Name>
            </Step>
            <Step>
                <Name>Raise-Fault-1</Name>
                <Condition>
                    request.queryparam.email is null 
                </Condition>
            </Step>
            <Step>
                <Name>Set-Target-Endpoint-Query-Parameters</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPProxyConnection>
        <BasePath>/customers</BasePath>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>

,

How to raise a fault if a query parameter is missing or empty?

I have a URL which needs to take email as a query parameter and if the parameter is missing or empty it needs to raise a fault.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>Verify-API-Key-1</Name>
            </Step>
            <Step>
                <Name>remove-query-param-apikey</Name>
            </Step>
            <Step>
                <Name>Raise-Fault-1</Name>
                <Condition>
                    request.queryparam.email is null 
                </Condition>
            </Step>
            <Step>
                <Name>Set-Target-Endpoint-Query-Parameters</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPProxyConnection>
        <BasePath>/customers</BasePath>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>

It does't seem to work; please help.

Solved Solved
0 3 1,595
1 ACCEPTED SOLUTION

To be safe, it also helps to check for null or empty parameters. Your condition should look like this:

<Condition>(request.queryparam.email = null) or (request.queryparam.email = "")</Condition>

If you are still having trouble, do a trace. The step should show the expression, the result of evaluating it, and the variables used for evaluating the expression.

View solution in original post

3 REPLIES 3