Use Variable in Text Request Body

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


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.

Hello @faisalfahmad, Welcome to community :wave:

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 of your scope and that can be used inside the body.

For example:

If I am generating the signature using random variables then I need to paste the below snippet under pre-request section,

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 {{}}


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

1 Like

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

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?

@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.


pm.test("Signature Validation", function () {