How to get to request parameters in Postman?

Deddiekoel picture Deddiekoel · May 22, 2017 · Viewed 51.4k times · Source

I'm writing tests for Postman which in general works pretty easily. However, I now want to access some of the data of the request, a query parameter to be exact. You can access the request URL through the "request.url" object which returns a String. Is there an easy way in Postman to parse this URL string to access the query parameter(s)?

Answer

bbjay picture bbjay · Jan 30, 2018

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});