Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Postman REST: reusing response values as request params in collections?

Tags:

rest

postman

I'm playing around with Postman REST extension's collections feature.

I have 2 requests: the 1st returns a sessionId in its response body and the 2nd requires the {{sessionId}} value as query param. Can I tell Postman to save the body of the 1st response to the {{sessionId}} variable?

I currently have to a) execute 1st request and b) copy response body and paste it as a value of the 2nd request's query param every time...

thanks, -nikita

like image 672
Nikita Avatar asked Jan 06 '14 18:01

Nikita


People also ask

How do you store API response in Postman?

There are 2 ways of saving the response to a file: Click on the small down arrow besides the "Send" button, this will show the "Send and Download" button. Click on it and postman will ask you where to save the response, when the request is done.


1 Answers

Absolutely Yes! Here is a json example: I added the following to the Tests Tab of the first request:

var data = JSON.parse(responseBody);

postman.setGlobalVariable("session_id", data['session_id']); 

Basically retrieving the data from responseBody and set it as a global variable

Then in the second request, the URL would be something like this:

http://{{whateverhost}}/api/v1/somefunction/{{session_id}}

Hope this helps. Cheers

like image 149
Yu Wang Avatar answered Oct 05 '22 01:10

Yu Wang