# Collection Variable as response from Mock Server

**URL:** <https://community.postman.com/t/collection-variable-as-response-from-mock-server/28578>\
**Category:** Help Hub\
**Created:** [October 8, 2021, 11:38am UTC](https://community.postman.com/t/collection-variable-as-response-from-mock-server/28578 "2021-10-08T11:38:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbahadur](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@bbahadur](https://community.postman.com/u/bbahadur)\
**Post date:** [October 8, 2021, 11:38am UTC](https://community.postman.com/t/collection-variable-as-response-from-mock-server/28578/1 "2021-10-08T11:38:36Z")

</div>

> **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](https://learning.postman.com/docs/design-apis/mock-apis/mocks/overview) and [Create a mock](https://learning.postman.com/docs/design-apis/mock-apis/mocks/create-a-mock).  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) can build and run mocks for you.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

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

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/f/fd773d22b84474879354950efe70c7f631bcc4ff.png)

Here is the example body I am setting

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/6/66ae8e1035b6732977f5c1868fd1f79c306336db.png)

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

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/7/7e91532ca180f7199f69b7fde8f9316630a4150f.png)

Thanks in advance for helping.

---

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [October 8, 2021, 6:59pm UTC](https://community.postman.com/t/collection-variable-as-response-from-mock-server/28578/2 "2021-10-08T18:59:40Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![bbahadur](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@bbahadur](https://community.postman.com/u/bbahadur)\
**Post date:** [October 11, 2021, 7:25am UTC](https://community.postman.com/t/collection-variable-as-response-from-mock-server/28578/3 "2021-10-11T07:25:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bbahadur](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@bbahadur](https://community.postman.com/u/bbahadur)\
**Post date:** [October 15, 2021, 9:17am UTC](https://community.postman.com/t/collection-variable-as-response-from-mock-server/28578/4 "2021-10-15T09:17:12Z")

</div>

Ended up using **Environment Variable** to get my task done. Thanks to solutions provided here → [Mock Server - Using Variables in Example Response](https://community.postman.com/t/mock-server-using-variables-in-example-response/2594)
