# Modify query param in pre-request script

**URL:** <https://community.postman.com/t/modify-query-param-in-pre-request-script/8880>\
**Category:** Help Hub\
**Tags:** pre-request\
**Created:** [November 8, 2019, 3:33pm UTC](https://community.postman.com/t/modify-query-param-in-pre-request-script/8880 "2019-11-08T15:33:31Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![mbuecher](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mbuecher](https://community.postman.com/u/mbuecher)\
**Post date:** [November 25, 2021, 4:10pm UTC](https://community.postman.com/t/modify-query-param-in-pre-request-script/8880/5 "2021-11-25T16:10:47Z")

</div>

What actually worked for me all the time was:

```auto
//console.log("----- Encode query string");
//console.log("Input: " + pm.request.url.query.toString());
var querycount = pm.request.url.query.count();
for(let i = 0; i < querycount; i++) {
  //console.log(i + "/" + pm.request.url.query.idx(i).key + ": " + encodeURIComponent(pm.request.url.query.idx(i).value));
  pm.request.url.query.idx(i).value = encodeURIComponent(pm.request.url.query.idx(i).value);
}
//console.log("Output: " + pm.request.url.query.toString());

```

---

_[View the full topic](https://community.postman.com/t/modify-query-param-in-pre-request-script/8880)._
