# Use Variable in Text Request Body

**URL:** <https://community.postman.com/t/use-variable-in-text-request-body/19587>\
**Category:** Help Hub\
**Created:** [January 27, 2021, 5:28am UTC](https://community.postman.com/t/use-variable-in-text-request-body/19587 "2021-01-27T05:28:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![faisalfahmad](https://avatars.discourse-cdn.com/v4/letter/f/8e7dd6/32.png) [@faisalfahmad](https://community.postman.com/u/faisalfahmad)\
**Post date:** [January 27, 2021, 5:28am UTC](https://community.postman.com/t/use-variable-in-text-request-body/19587/1 "2021-01-27T05:28:16Z")

</div>

Hi - I am making a POST Request to an API which takes in raw text body e.g.

x\_account\_id=abc&x\_amount=892.5&x\_currency=CAD&x\_customer\_billing\_address1=4414++A+Avenue&x\_customer\_billing\_city=Edmonton&x\_signature=abc

I am calculating the signature using pre-req script but not sure how to use the value from pre-req script in my request body.

 ![POSTMAN-sig](https://us1.discourse-cdn.com/getpostman/original/3X/a/d/ada1610d6f9d601a230d5cc401d81e204ef03f85.png)

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [January 27, 2021, 9:13am UTC](https://community.postman.com/t/use-variable-in-text-request-body/19587/2 "2021-01-27T09:13:35Z")

</div>

Hello @faisalfahmad, Welcome to community 👋

Could you please share what you have written as part of the pre-req script section?

Because based on that the expected value can be assigned to the [variable](https://learning.postman.com/docs/sending-requests/variables/) of your scope and that can be used inside the body.

For example:

If I am generating the signature using [random variables](https://learning.postman.com/docs/writing-scripts/script-references/variables-list/) then I need to paste the below snippet under pre-request section,

```auto
pm.environment.set("signature", pm.variables.replaceIn('{{$randomFirstName}}'));

```

in you case if you are already generating the value for signature field, assign that value to the variable signature.

And then in your body you need to access the variable using {{}}

```auto
x_signature={{signature}}

```

Please share us more details/screenshots if you still have issue 🙂

---

<div class="post-metadata">

**Author:** ![faisalfahmad](https://avatars.discourse-cdn.com/v4/letter/f/8e7dd6/32.png) [@faisalfahmad](https://community.postman.com/u/faisalfahmad)\
**Post date:** [January 27, 2021, 5:49pm UTC](https://community.postman.com/t/use-variable-in-text-request-body/19587/3 "2021-01-27T17:49:46Z")

</div>

@bpricilla I just added snippet of how I am setting signature in pre-req

 ![Signature1](https://us1.discourse-cdn.com/getpostman/original/3X/9/d/9d40411974a1fe04d0e83b6f40a8d37b347f33b7.png)

In the Request Body I am using x\_signature={{signature}}

Does this sound correct? Also how do I debug or console.log the request postman is sending to check if POSTMAN is replacing the {{signature}} with actual variable?

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [January 28, 2021, 1:52am UTC](https://community.postman.com/t/use-variable-in-text-request-body/19587/4 "2021-01-28T01:52:12Z")

</div>

@faisalfahmad yes correct, you need to add the variable that way.

so in your pre-req script you can add the console log statements to check them manually and can write a assertion to check them.

```auto
console.log(Signature);
console.log(pm.environment.get("signature"));

pm.test("Signature Validation", function () {
pm.expect(Signature).to.eql(pm.environment.get("signature"));
});

```
