Mile Stanislavov
Mile Stanislavov

Reputation: 33

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!

Upvotes: 1

Views: 2920

Answers (1)

lucas-nguyen-17
lucas-nguyen-17

Reputation: 5917

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);

Upvotes: 2

Related Questions