Do this in a JS Policy in any proxy:
print( undefined, typeof undefined ); print( request.queryParams.fake, typeof request.queryParams.fake, !!request.queryParams.fake );
Trace a call to the proxy without setting ?fake. The output is:
undefined undefined undefined object true
The second line should be "undefined undefined false". I guess this is an error in the magic queryParams object.
I tried checking if a query param is set or not with
if ( !request.queryParams.id )
Which will not work, obviously. A workaround is
if ( 'id' in request.queryParams && request.queryParams.id !== '' )
(running on-premise 4.15.07.00)
Please, Apigee, fix your magic Java objects and use standard JS - I'm fearful of bugs in .asJSON and the likes now.
EDIT
Additionally,
request.queryParams.id.length
fails with
Execution of check failed with error: Javascript runtime error: "TypeError: Cannot find default value for object. (check_js#6). at line 6 "
even if ?id=1 is set.
@Morris Brodersen To access the variables set by Apigee from within a javascript policy you need to use context.getVariable('myvariable').
Try changing your script to the below one and you should get the desired results:
print( context.getVariable("request.queryparams.fake"), typeof context.getVariable("request.queryparams.fake"), !!context.getVariable("request.queryparams.fake") );
Thanks, that might be a better workaround. However http://docs.apigee.com/api-services/reference/javascript-object-model clearly says "Note: You can also use the "shorthand" objectrequest
to access these properties in a request flow. The request
object refers to eithercontext.proxyRequest
or context.targetRequest
, depending on where in the flow your JavaScript code executes." so the above is still invalid/buggy behavior.
@Morris Brodersen - JS is case-sensitive.
Is it possible that you are using {{request.queryParams}} instead of the required {{request.queryparam}} ??
I think you want:
if ( !request.queryparam.id ) ...
Nope - not queryparamS
queryparam
request.queryparam.id
no s
no capital
@Floyd Jones see above re: docs.
@Floyd Jones - be careful. Maybe a EBCAK