How to get to request parameters in Postman?

I have been looking to access the request params for writing tests (in POSTMAN). I ended up parsing the request.url which is available in POSTMAN.

const paramsString = request.url.split('?')[1];
const eachParamArray = paramsString.split('&');
let params = {};
eachParamArray.forEach((param) => {
    const key = param.split('=')[0];
    const value = param.split('=')[1];
    Object.assign(params, {[key]: value});
});
console.log(params); // this is object with request params as key value pairs

POSTMAN CLIENT CONSOLE RESPONSE

edit: Added Github Gist


The pm.request.url.query.all() array holds all query params as objects. To get the parameters as a dictionary you can use:

var query = {};
pm.request.url.query.all().forEach((param) => { query[param.key] = param.value});