Skip to content
Advertisement

how to access raw data in Postman(Request section)?

So I want to print out the client Name and the client Email as string values through the Postman console, but when I call the method I get a the array but with undefined values.

const res = pm.response.json();
const req = pm.request.toJSON();
let user = [req.body.raw.clientName, req.body.raw.clientName];
console.log(user);

Thank you very much!

Advertisement

Answer

You can get request body raw using:

pm.request.body.raw

For example:

You have request body in postman:

{
    "foo": "bar"
}

You want to access value of foo in tab Tests:

const req = JSON.parse(pm.request.body.raw)
console.log(req.foo);
Advertisement