# Need help in passing variable in body

**URL:** <https://community.postman.com/t/need-help-in-passing-variable-in-body/36364>\
**Category:** Help Hub\
**Created:** [June 20, 2022, 12:08am UTC](https://community.postman.com/t/need-help-in-passing-variable-in-body/36364 "2022-06-20T00:08:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rekha135](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@rekha135](https://community.postman.com/u/rekha135)\
**Post date:** [June 20, 2022, 12:08am UTC](https://community.postman.com/t/need-help-in-passing-variable-in-body/36364/1 "2022-06-20T00:08:25Z")

</div>

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-just-getting-started-category/37) before creating a new topic.**

> Here’s an outline with best practices for making your inquiry.

_My question_:  
i have designed pre-requisite script as show below to generate random name field values  
let x = Math.random();  
let name = ‘Lauren’ + x;  
pm.globals.set(“name” ,name);

how can i pass this name variable in below body format  
{“parameterData”: “{"action": "Insert","name": "Lauren"}”}

_Details (like screenshots)_:

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

_How I found the problem_:

_I’ve already tried_:

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 20, 2022, 10:49am UTC](https://community.postman.com/t/need-help-in-passing-variable-in-body/36364/2 "2022-06-20T10:49:56Z")

</div>

Hi @rekha135

You would just call it like you would a normal variable;

Example;

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

Output;

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

Also, are you aware of the dynamic variables available for this sort of thing?

> **[Dynamic variables | Postman Learning Center](https://learning.postman.com/docs/writing-scripts/script-references/variables-list/)**
>
> Dynamic variables: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

Example;

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

Output;

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

Hope this helps.

---

<div class="post-metadata">

**Author:** ![rekha135](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@rekha135](https://community.postman.com/u/rekha135)\
**Post date:** [June 20, 2022, 3:29pm UTC](https://community.postman.com/t/need-help-in-passing-variable-in-body/36364/3 "2022-06-20T15:29:40Z")

</div>

Thanks for your revert ,but as my input body takes as whole string with backward slashes (" ") as shown in below request body so how can i pass name as variable in request body .  
{“parameterData”: “{“action”: “Insert”,“name”: “Lauren”}”}

if i will try passing variable as name in below request body then i am getting error in response : (

{“parameterData”: “{“action”: “Insert”,{{name}}”}

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

---

<div class="post-metadata">

**Author:** ![rekha135](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@rekha135](https://community.postman.com/u/rekha135)\
**Post date:** [June 20, 2022, 3:31pm UTC](https://community.postman.com/t/need-help-in-passing-variable-in-body/36364/4 "2022-06-20T15:31:47Z")

</div>

Please advise any way to pass this variable as input body request body is defined as whole string rather than plain vanilla json body ☹

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 20, 2022, 5:03pm UTC](https://community.postman.com/t/need-help-in-passing-variable-in-body/36364/5 "2022-06-20T17:03:24Z")

</div>

Looks like you’re missing some quotes and a closing bracket…

* * *

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

* * *

Try;

```auto
{"parameterData": "{\"action\": \"Insert\",\"{{name}}\"}"}

```

---

<div class="post-metadata">

**Author:** ![rekha135](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@rekha135](https://community.postman.com/u/rekha135)\
**Post date:** [June 20, 2022, 7:09pm UTC](https://community.postman.com/t/need-help-in-passing-variable-in-body/36364/6 "2022-06-20T19:09:40Z")

</div>

> [@w4dd325](#):
>
> `{"parameterData": "{\"action\": \"Insert\",\"{{name}}\"}"}`

same error ☹

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

---

<div class="post-metadata">

**Author:** ![rekha135](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@rekha135](https://community.postman.com/u/rekha135)\
**Post date:** [June 20, 2022, 7:31pm UTC](https://community.postman.com/t/need-help-in-passing-variable-in-body/36364/7 "2022-06-20T19:31:21Z")

</div>

Thanks James ,you are really helpful so far .i am still not able to post this request body successfully with “name” as variable .please assist me

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 20, 2022, 7:32pm UTC](https://community.postman.com/t/need-help-in-passing-variable-in-body/36364/8 "2022-06-20T19:32:01Z")

</div>

I made a mistake when comparing to your original question, I missed a property.

Try;

```auto
{"parameterData": "{\"action\": \"Insert\",\"name\": \"{{name}}\"}"}

```

* * *

Are there any docs you are working from? 1

---

<div class="post-metadata">

**Author:** ![rekha135](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@rekha135](https://community.postman.com/u/rekha135)\
**Post date:** [June 20, 2022, 8:44pm UTC](https://community.postman.com/t/need-help-in-passing-variable-in-body/36364/9 "2022-06-20T20:44:08Z")

</div>

> [@w4dd325](#):
>
> `{"parameterData": "{\"action\": \"Insert\",\"name\": \"{{name}}\"}"}`

Thank you James ,you are awesome .my issue resolved now
