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.
JavaScript
x
5
1
const res = pm.response.json();
2
const req = pm.request.toJSON();
3
let user = [req.body.raw.clientName, req.body.raw.clientName];
4
console.log(user);
5
Thank you very much!
Advertisement
Answer
You can get request body raw using:
JavaScript
1
2
1
pm.request.body.raw
2
For example:
You have request body in postman:
JavaScript
1
4
1
{
2
"foo": "bar"
3
}
4
You want to access value of foo
in tab Tests:
JavaScript
1
3
1
const req = JSON.parse(pm.request.body.raw)
2
console.log(req.foo);
3