Postman Tutorial Part 51 -Printing Request Body & Response Body in Postman Console

As a part of Postman Tutorial – End to End , in this post, we will learn “How to print Request and Response body in console?”.

We have already learnt to retrieve Request and Response body in Postman but as this is a frequently asked interview question on Postman, so I am combining concepts in a small post separately.

Code to get Request Body:-

var jsonReq = JSON.parse(pm.request.body.raw);

var jsonRes = pm.response.json();

To print just put in console.log(). To extract value from JSON body, you can write json path which we have seen already. You can refer those concepts here.

Complete code:-

// "raw" gives string. So need to parse in to JSON
 var jsonReq = JSON.parse(pm.request.body.raw);
 var jsonRes = pm.response.json();
 console.log("Request body is as below: ")
 console.log(jsonReq)
 console.log("Response body is as below: ")
 console.log(jsonRes)

Postman Console:-

However, you can get all these details by clicking on URI.

You can import example collection from here.

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.

Leave a Reply

Your email address will not be published. Required fields are marked *