We are working on a javascript file that will manipulate query parameters of an incoming request based on certain requirements.
In general, can you tell me how to add and remove query parameters using only javascript and not the assign message policy?
Solved! Go to Solution.
We can use the context.setVariable and context.removeVariable APIs to add and remove the query parameters from the request via the JavaScript policy. Below are the code snippets that suggests how it can be done.
var count = 100; context.setVariable("request.queryparam.count", count);
var username = 'Username'; context.removeVariable("request.queryparam." + username);
// 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);
We can use the context.setVariable and context.removeVariable APIs to add and remove the query parameters from the request via the JavaScript policy. Below are the code snippets that suggests how it can be done.
var count = 100; context.setVariable("request.queryparam.count", count);
var username = 'Username'; context.removeVariable("request.queryparam." + username);
// 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);
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |