Remove All Query params from request

Not applicable

Hi team,

How can i remove all query parameters from request before sending it to target endpoint.

I applied Assign message policy.

<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-RemoveQueryParams"> <DisplayName>AM-RemoveQueryParams</DisplayName> <AssignVariable> <Name>target.copy.pathsuffix</Name> <Value>false</Value> </AssignVariable> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="request"/> </AssignMessage>

Applied policy on target proxy and request flow.

But it doesn't work.

thanks.

0 2 2,654
2 REPLIES 2

Try using below JS Policy in TargetEndpoint Preflow,

 // Print the request before removing the query parameter
context.setVariable("MyRequest1", request);


// Get all the query parameter names
var queryParamNames = context.getVariable('request.queryparams.names');


//convert it to string array.


queryParamNames = queryParamNames.toArray();


for (var i = 0; i < queryParamNames.length; i++) {
   print("queryParamName = " + queryParamNames[i]);
   // Remove the query parameter from the request
   context.removeVariable("request.queryparam." + queryParamNames[i]);
}


// Print the request after removing the query parameters
context.setVariable("MyRequest2", request);

This was written by Amar @Devagowda in some early posts.

HI @abnamro Test

Try adding the following code to your Assign Message policy

<Remove><QueryParams/></Remove>

Its documented as well. Check the "<Remove>/<QueryParams> element" in this page