What am I doing:
Client sends request with multiple query parameters. If a parameter does not exist (key & value) I will supply them with a defaulted value. To determine if the client has sent in the correct query parameter I am using JavaScript to run the "request.queryparams.names" and will output all of the query parameters sent in by the client. I now need to parse the output of "request.queryparams.names" to determine if specific query parameter was sent.
What am I seeing:
As of right now I see the following when running "request.queryparams.names":
request.queryparams.names [branchId, productId, customerId, shipWhseId]
I have tried several times to check against specific values using "request.queryparam.<paramname>" but absolutely nothing gets returned. So now I am trying to parse output of "request.queryparams.names" to find out if query param name exists or not.
Any help on this would be appreciated.
The javascript below works
var queryparamnames = context.getVariable("request.queryparams.names"); var a = queryparamnames.toArray(); print("numOfQueryParams="+a.length); for (var i=0; i<a.length; i++) { print(context.getVariable("request.queryparam."+a[i]));}
You can also take a look at an older post on how to parse the query parameters in JS-
https://community.apigee.com/questions/12782/how-do-you-iterate-collection-from-requestquerypar.html
Hope that helps
So I figured out how to do what I was looking to do with the following code block:
context.setVariable("jsparamA", context.getVariable("request.queryparam.<defaultparamA>")) if (context.getVariable("jsparamA") === null || context.getVariable('jsparamA') === "") { context.setVariable("jsparamA", context.getVariable("<defaultparamA>")); }
knowing how "null" is being treated in regards to queryparameters within the javascript was the real issue I was having. Hope this may help someone else having a similar problem.
Thanks for all your assistance....
User | Count |
---|---|
7 | |
2 | |
2 | |
2 | |
1 |