Setting variables from query string parameters

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? Or even as a POST request.

Details:

I run a documentation portal 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.

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

You can set variables in prerequest test, for example:

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

1 Like

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.

Hello @vadimberman, Welcome to the Community :partying_face:

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 :blush:

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());
2 Likes

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.

3 Likes

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

Any chance they can be read, too?

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

3 Likes

HI @vadimberman, I think the documentation page 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.

3 Likes