I am sending raw POST request with application/json data to server in Postman. I need to work with this JSON object and append some data in pre-request script. However I can only find how to access environmental variables, not request body. Anybody knows, please? Thanks!
1 Answers
2
votes
"I can only find how to access environmental variables, not request body"
You can access request body in Pre-request Script via pm.request.body
.
Unfortunately, you cannot change it through script (at least not supported in Jul. 2018). Please check this thread for some previous discussion.
However, there is a workaround: you can make the whole request body use environment variable, such as {{reqBody}}
, and edit that variable in Pre-request Script panel. For example:
var defaultReqBody = {
a: 42
};
//Edit defaultReqBody ...
pm.environment.set("reqBody", JSON.stringify(defaultReqBody));