faisalfahmad
(Faisal Fayyaz Ahmad)
January 27, 2021, 5:28am
1
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.
bpricilla
(Pricilla B)
January 27, 2021, 9:13am
2
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 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 {{}}
x_signature={{signature}}
Please share us more details/screenshots if you still have issue
1 Like
faisalfahmad
(Faisal Fayyaz Ahmad)
January 27, 2021, 5:49pm
3
@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?
bpricilla
(Pricilla B)
January 28, 2021, 1:52am
4
@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.
console.log(Signature);
console.log(pm.environment.get("signature"));
pm.test("Signature Validation", function () {
pm.expect(Signature).to.eql(pm.environment.get("signature"));
});