Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get to request parameters in Postman?

Tags:

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)?

like image 622
Deddiekoel Avatar asked May 22 '17 08:05

Deddiekoel


2 Answers

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}); 
like image 188
bbjay Avatar answered Oct 26 '22 20:10

bbjay


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

like image 36
Sudarsan GP Avatar answered Oct 26 '22 21:10

Sudarsan GP