8
votes

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

1
I use Postman quite a bit, but as far as I know, it doesn't have that capability. It would be an interesting enhancement, though. - Andy Dennie

1 Answers

7
votes

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