Mock Server - Using Variables in Example Response

Short Story

You have to have your environment variables set in the init value columns if you want the mock server to see them.

Long story

So, this took me a while to figure out why I couldn’t make the whole mock env’s work … and as it makes sense once I thought about … I thought I would pass it along here so that others might not have the same issue I have :slight_smile:

So, first off, I tend to not use the environment variables like others seem to :stuck_out_tongue: I set all my environment variables that are “dynamic” through a pre-script in the “setup” folder that I make for all my collections … there is a corresponding “takedown” folder that removes all the stuff I did. For that reason, all most all my variables that are in “current” set.

Issue

So … for the longest time I couldn’t get anything but the dynamic global variables like $randomBankAccount or $randomUUID to work.

The fix and reason for it

Then I read one of the posts about how they couldn’t figure out how to get the variables to not persist so that if a test were running twice then the variables would step on each other. That got me thinking along the right track and it ALL came clear … the current variables CAN’T be shared with the mock server cause they aren’t serialized or stored on the postman servers.

If only

Thus, I am trying to figure out how to “force” through code, the variables to the mock server so it can be used. Personally, I am still thinking that giving it ( the mock server instance ) access to headers is a simple and obvious thing to do is give something like: {{$header['the_header_you_want']}} as a form of a global expand like the $random is.
Thoughts?

6 Likes