Raw json body how to add variable?

Hi @kizildagcenk, you’re using the correct method to set the variable in the pre-request script.
One thing I’d like to point out on the last line is that you can use pm.environment.set("Signature", encryption);
This is the new API and I recommend using it.

Also, in the raw body, you’ve to surround the Signature variable with quotes.
So your raw body actually becomes the following:

{
    "referenceId": "022078925508",
    "productCode": "001002461285",
    "quantity": "1",
    "version": "V1",
    "signature": "{{Signature}}", // notice the quotes here around the variable
    "applicationCode": "52e7cf966b724749a7c4efadc3727ed7"
}

Now run your script and it should work as expected.

3 Likes