# Setting variables from query string parameters

**URL:** <https://community.postman.com/t/setting-variables-from-query-string-parameters/25076>\
**Category:** Help Hub\
**Tags:** documentation, variables, authentication\
**Created:** [June 22, 2021, 8:44am UTC](https://community.postman.com/t/setting-variables-from-query-string-parameters/25076 "2021-06-22T08:44:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vadimberman](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vadimberman/32/8975_2.png) [@vadimberman](https://community.postman.com/u/vadimberman)\
**Post date:** [June 22, 2021, 8:44am UTC](https://community.postman.com/t/setting-variables-from-query-string-parameters/25076/1 "2021-06-22T08:44:24Z")

</div>

_My question_:

Is there a way to set a variable (global or environment, does not matter) from outside of the documentation portal upon launching it? E.g. [mydocportal.com?apiKey=blahblahblah](http://mydocportal.com?apiKey=blahblahblah)? Or even as a POST request.

_Details_:

I run a [documentation portal](https://docs.tisane.ai) accessible from my website. The website has the API key, and I want to pass it on to the documentation portal. I also want to pass another parameter (language based on the locale language in the website).

_I’ve already tried_:

Looking up in Google, Stack Overflow, and documentation.

---

<div class="post-metadata">

**Author:** ![khan\_aktas](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/khan_aktas/32/8816_2.png) [@khan\_aktas](https://community.postman.com/u/khan_aktas)\
**Post date:** [June 22, 2021, 1:26pm UTC](https://community.postman.com/t/setting-variables-from-query-string-parameters/25076/2 "2021-06-22T13:26:30Z")

</div>

Hello there, can you provide us more information, I honestly cannot understand what you need.

You can set variables in prerequest test, for example:

```auto
pm.collectionVariables.set("Isotime", pm.variables.replaceIn('{{$isoTimestamp}}'));

```

You can set variables via postman UI  
You can run a request before main requests that will receive a token, after that you can parse the response and write it to variables

---

<div class="post-metadata">

**Author:** ![vadimberman](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vadimberman/32/8975_2.png) [@vadimberman](https://community.postman.com/u/vadimberman)\
**Post date:** [June 23, 2021, 6:37am UTC](https://community.postman.com/t/setting-variables-from-query-string-parameters/25076/3 "2021-06-23T06:37:01Z")

</div>

Thanks, @khan_aktas.

I want to interact with the Postman web application (documentation portal) from outside. Prerequest test is interesting. Can it look at the URL that invoked it though? Are there system variables like “$current\_url” or “$query\_params”?

Or even read variable values from cookies.

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [June 23, 2021, 9:53am UTC](https://community.postman.com/t/setting-variables-from-query-string-parameters/25076/4 "2021-06-23T09:53:38Z")

</div>

Hello @vadimberman, Welcome to the Community 🥳

I am sorry, I did not understand the full context here, but may be the below snippets can help you to get the url and params 😊

```auto
console.log(pm.request.url.query.all());
console.log(pm.request.url.path);
console.log(pm.request.url.query.toObject());
console.log(pm.request.url.query.toString());

```

---

<div class="post-metadata">

**Author:** ![vadimberman](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vadimberman/32/8975_2.png) [@vadimberman](https://community.postman.com/u/vadimberman)\
**Post date:** [June 23, 2021, 10:06am UTC](https://community.postman.com/t/setting-variables-from-query-string-parameters/25076/5 "2021-06-23T10:06:13Z")

</div>

Hi @bpricilla,

Thank you! And yes, that’s what I wanted. That should solve it.

I just need to assign the result to the variable.

---

<div class="post-metadata">

**Author:** ![vadimberman](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vadimberman/32/8975_2.png) [@vadimberman](https://community.postman.com/u/vadimberman)\
**Post date:** [June 23, 2021, 12:00pm UTC](https://community.postman.com/t/setting-variables-from-query-string-parameters/25076/6 "2021-06-23T12:00:32Z")

</div>

Sorry, what about local storage and cookies, @bpricilla?

Any chance they can be read, too?

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [June 23, 2021, 3:50pm UTC](https://community.postman.com/t/setting-variables-from-query-string-parameters/25076/7 "2021-06-23T15:50:40Z")

</div>

`console.log(pm.cookies.all())`

postman has the autocomplete or intellisense feature so if you just type pm. it will show all available methods. cookies is one of thos

---

<div class="post-metadata">

**Author:** ![sean.keegan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/sean.keegan/32/6353_2.png) [@sean.keegan](https://community.postman.com/u/sean.keegan)\
**Post date:** [June 23, 2021, 7:53pm UTC](https://community.postman.com/t/setting-variables-from-query-string-parameters/25076/8 "2021-06-23T19:53:09Z")

</div>

HI @vadimberman, I think the [documentation page](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#the-pm-object) that talks about the `pm` object may be helpful for you! It lists all of the methods you can use in the Pre-request and Tests tabs for testing your request and response data.
