# request.queryParams bug

**URL:** <https://discuss.google.dev/t/request-queryparams-bug/14286>\
**Category:** Apigee\
**Tags:** api-runtime\
**Created:** [January 29, 2016, 5:37pm UTC](https://discuss.google.dev/t/request-queryparams-bug/14286 "2016-01-29T17:37:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 29, 2016, 5:37pm UTC](https://discuss.google.dev/t/request-queryparams-bug/14286/1 "2016-01-29T17:37:54Z")

</div>

Do this in a JS Policy in any proxy:

```auto
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:

```auto
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

```auto
if ( !request.queryParams.id )

```

Which will not work, obviously. A workaround is

```auto
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,

```auto
request.queryParams.id.length

```

fails with

```auto
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.

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [February 2, 2016, 12:34am UTC](https://discuss.google.dev/t/request-queryparams-bug/14286/2 "2016-02-02T00:34:11Z")

</div>

[@Morris Brodersen](https://community.apigee.com/users/3186/morrisbrodersencf.html) 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:

```auto
print( context.getVariable("request.queryparams.fake"), typeof context.getVariable("request.queryparams.fake"), !!context.getVariable("request.queryparams.fake") );

```

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [February 2, 2016, 9:15am UTC](https://discuss.google.dev/t/request-queryparams-bug/14286/3 "2016-02-02T09:15:35Z")

</div>

Thanks, that might be a better workaround. However [http://docs.apigee.com/api-services/reference/javascript-object-model](http://docs.apigee.com/api-services/reference/javascript-object-model) clearly says “ **Note:** You can also use the “shorthand” object`request` to access these properties in a request flow. The `request` object refers to either`context.proxyRequest` or `context.targetRequest`, depending on where in the flow your JavaScript code executes.” so the above is still invalid/buggy behavior.

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [February 3, 2016, 12:58am UTC](https://discuss.google.dev/t/request-queryparams-bug/14286/4 "2016-02-03T00:58:58Z")

</div>

[@Floyd Jones](https://community.apigee.com/users/202/fjonesapigeecom.html) see above re: docs.

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [February 8, 2016, 6:00pm UTC](https://discuss.google.dev/t/request-queryparams-bug/14286/5 "2016-02-08T18:00:49Z")

</div>

[@Morris Brodersen](https://community.apigee.com/users/3186/morrisbrodersencf.html) - JS is case-sensitive.

Is it possible that you are using {{request.queryParams}} instead of the required {{request.queryparam}} ??

I think you want:

```auto
if ( !request.queryparam.id ) ...

```

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [February 8, 2016, 6:01pm UTC](https://discuss.google.dev/t/request-queryparams-bug/14286/6 "2016-02-08T18:01:19Z")

</div>

[@Floyd Jones](https://community.apigee.com/users/202/fjonesapigeecom.html) - be careful. Maybe a EBCAK

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [February 8, 2016, 6:05pm UTC](https://discuss.google.dev/t/request-queryparams-bug/14286/7 "2016-02-08T18:05:32Z")

</div>

Nope - not queryparamS

queryparam

request.queryparam.id

no s

no capital
