Collection Variable as response from 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.

Hello!

I am trying to set a collection variable as a response from mock server but am unable to get the value.
Here is the collection variable

Here is the example body I am setting

And I am not sure what I am doing wrong, as the response is not loading the variable value

Thanks in advance for helping.

Hi @bbahadur,

Can you please check if you have saved the collection.

Collection Variables will not reflect unless you have saved the collection.

Hope this helps :slight_smile:

Hey @pranavdavar ,

Thanks for the response.
Yes, I have saved the collection, still the collection variable value is not reflected in response.
I tried working with a dynamic variable and it’s value is shown perfectly in the response.
Guess there’s some issue with the collection variable.

Ended up using Environment Variable to get my task done. Thanks to solutions provided here → Mock Server - Using Variables in Example Response