Save response to global variable for use with other queries

I am trying to retrieve a get result and automatically store it in an environment variable for use by other queries. Does anyone have a working example that would help?

Hey @larry,

Something like this should work. Under the Tests tab, write:

pm.environment.set('savedResponse', JSON.stringify(pm.response.json()));

Then to access it in a subsequent request, you can use:

const saved = JSON.parse(pm.environment.get('savedResponse'));

in a script or you can just use normal variable syntax, such as {{savedResponse}} in other parts of the Request that support variable substitution.

Hope this helps.



1 Like