Saving request data sent to mock server

Archived topic — some details may be out of date.
Mock servers built from saved collection examples are still supported. Postman now also has code-based mocks: JavaScript request handlers plus a config.yaml, stored as files in your Git repository, which you can run locally or deploy. Create one in the app, or use the Postman CLI to generate one from an OpenAPI spec, collection or dataset (postman mock generate) and run it (postman mock run). See About mocks and Create a mock.
Working with an AI coding agent? The Postman plugin can build and run mocks for you.
For current help, see the Postman docs, try the free Postman tools (no account needed), or join us on Discord.

I am trying to implement the following scenario in the postman.

Scenario:

  1. Setup a mock server

  2. Send a request to the mock server

  3. Access the data received on the mock server

  4. Store that data to a global variable and use it later in the testing

Step 1 and step 2 are done. but stuck at step 3.

How should I access the data from the request sent to the mock server?

Can you maybe explain which problem / scenario you are trying to solve?

Hi vdespa,
I haven’t found answer but I am dealing similar usecase keyulpax.

I have setup mock server using postman I call it e.g. by this url {{url}}/get?foo=bar.
If I call requeste from postman it is fine and I can process parameter by “Tests” in Request.
But when the url is called from browser, I can’t use Pre-Request Script or Tests anymore.
The aim is to catch parameters from url directly in response as save it as variable. Is that possible?

Thanks

@tra - you can use scripts and variables only within Postman.