How can I use pre-request script's result in request's body?

I know I can set variable in script and use it in body. but I don’t want to save the variable, I want to use “return”, this works in similar tools.

example of what I want to achieve :

pre-request script :
return “hello from script”

request body :
{“message” : {{***}}

is it possible? what there should be instead of ***

The intended way is to use variables. If you really don’t like them being saved, you can always use pm.variables.set("var", "hello from script"); so they don’t show up in your collection or environment and will be deleted after the request has finished running. Then your request’s body can be { "message" : {{var}} }.

1 Like