# ReferenceError using url package

**URL:** <https://community.postman.com/t/referenceerror-using-url-package/13739>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [June 29, 2020, 7:45pm UTC](https://community.postman.com/t/referenceerror-using-url-package/13739 "2020-06-29T19:45:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![msch](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@msch](https://community.postman.com/u/msch)\
**Post date:** [June 29, 2020, 7:45pm UTC](https://community.postman.com/t/referenceerror-using-url-package/13739/1 "2020-06-29T19:45:32Z")

</div>

My base issue is that I want to treat the query string from a redirect header as a dictionary. The [sandbox documentation](https://learning.postman.com/docs/postman/scripts/postman-sandbox-api-reference/) says that it supports the `url` package.

However, when I try to new up a `URL` object, it says `ReferenceError: URL is not defined`. I can use the legacy `url.parse` function, but that doesn’t get me access to the `URLSearchParams` class.

I tried the following code in both Postman and the Nodejs playground in Katacoda. Postman of course throws the above error, but it works in Katacoda.

```javascript
const url = require('url');
u = new URL('https://foo.com?bar=baz');
console.log(u);

```

I’m a noob at js, so I’m sure this is just some basic thing I don’t know about. I’m really hoping that this isn’t an undocumented incompatibility.

---

<div class="post-metadata">

**Author:** ![danielhofer](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@danielhofer](https://community.postman.com/u/danielhofer)\
**Post date:** [August 8, 2022, 9:11am UTC](https://community.postman.com/t/referenceerror-using-url-package/13739/2 "2022-08-08T09:11:42Z")

</div>

Hey,  
importing and using URL with require did not work for me, but I found a workaround:

try the following to add some query paramters to a url:

```auto
const sdk = require('postman-collection');
let myUrl = new sdk.Url('https://https://accounts.eu1.gigya.com/accounts.getJWT');
myUrl.query.add({"targetUID":pm.environment.get("sap_cdc_target_uid")});
myUrl.query.add({"apiKey":pm.environment.get("sap_cdc_target_uid")});
myUrl.query.add({"userKey":pm.environment.get("sap_user_key")});

```

This will add Query Paramters to the query property of type (PropertyList) [PropertyList - Postman Documentation](https://www.postmanlabs.com/postman-collection/PropertyList.html)

You can also access query string by index

`myUrl.query.idx(0).value = "newValue";`

> [@Modify query param in pre-request script](https://community.postman.com/t/modify-query-param-in-pre-request-script/8880/3):
>
> So I’m pretty new to postman scripting, but I think this might work for you. If I know the index of my parameter to update, as it seems you are wanting to do, I have been successful with pm.request.url.query.idx(0).value = "newValue";

Credits to: [How can we parse a URL in a pre-request script? · Issue #3059 · postmanlabs/postman-app-support · GitHub](https://github.com/postmanlabs/postman-app-support/issues/3059#issuecomment-323919460)  
Documentation: [Url - Postman Documentation](http://www.postmanlabs.com/postman-collection/Url.html)
