Following up here as mentioned. Now that you’ve created the environment variable and associated it to the Mock Server, in your particular case if you want to programmatically update the Environment Variable to then reflect the appropriate value in the response you can make use of a
pre-request script. More information can be found here:
Try the following and let me know if it helps. In your pre-request script, write the following:
let param = pm.request.url.query.toObject().depots;
What this does is that it takes the value of the Query Param,
depots and then assigns that value to the Environment Variable
So when you make the changes here:
Note that the Example response still references the Environment Variable:
The response will change. Please note that you’ll need to make sure to persists the current value to initial value in your settings:
Otherwise, the initial value won’t change and your response value won’t either. There may be a slight delay as the changes need to be synced and Mock Servers are essentially designed to server Static Content. I hope this helps. Feel free to follow up here if you still need help.
As a final note, the
pre-request script will work when making the request from the Native App. If you’re opening the Browser and making the request that way, unfortunately, the pre-request script will not run so the value of
depots will only reflect the last value in Initial Value. If that value isn’t changed (i.e. through re-request script ) then the response value won’t be the latest one. I hope this clarifies.