What is the best way to passthrough a fixed set of queryparams?

I have a API where I want to passthrough some queryparams from request to the target server. However, I want to passthrough only limited set of queryparams. Anything passed additionally, I want to strip it out / ignore it.

What is the best way to do this? Can I do it using just policies and without having to use Javascript?

example: request: sample.com/api?a=1&b=2&c=3&d=4&x=10 to target: target.com/api?a=1&b=1

When I use the assignmessage policy, I tried to <Remove> all queryparam and copy only the needed queryparams. However of course remove and copy don't go together and all queryparams are removed.

With just <Copy> the extra params go through to target.

With <Set> optional params go through as blank which I dont want. example: target.com/api?a=&b=1

0 1 356
1 REPLY 1

Dear @Prashanth Subrahmanyam ,

Yes , You are right. Remove & Copy don't go together. Same applies for remove & set also.

You need to split the logic into two different Assign Message Policies. Below policies works for your use case. Tested and it works. Possible using just policies without javascript.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
    <DisplayName>Assign Message-1</DisplayName>
    <Properties/>
    <Set>
        <QueryParams>
            <QueryParam name="b">{request.queryparam.a}</QueryParam>
        </QueryParams>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-2">
    <DisplayName>Assign Message-2</DisplayName>
    <AssignTo createNew="false" type="request"/>
    <Properties/>
    <Remove>
        <QueryParams>
            <QueryParam name="c"/>
            <QueryParam name="d"/>
            <QueryParam name="x"/>
        </QueryParams>
        <Payload/>
    </Remove>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

1010-screen-shot-2015-08-27-at-22104-pm.png

Cheers,

Anil Sagar