How can I access Request object in PostMan
for application/json request body, you would use the answer provided by Trung. However, for the form data, you need to simply access the body using request.data and then you can get your variables directly, like request.data.email or request.data.password
If you are doing it from a test script this is the syntax:
pm.test("Update env", function () {
var req = JSON.parse(pm.request.body.raw);
pm.environment.set("restaurantId", req.restaurantId);
var resp = pm.response.json();
pm.environment.set("restaurantId", resp.restaurantId);
});
After doing some research in Postman Sandbox
I finally found the answer for myself.
var reqBody = JSON.parse(request.data);
var resBody = JSON.parse(responseBody)
tests["Data"] = reqBody.restaurantId === resBody.restaurantId;
//this works for form-data:
var reqBody = request.data;
//this works for raw:
var reqBody = JSON.parse(request.data);