Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Postman Tutorial Part 50 – How to Retrieve Request Body in Postman

Posted on 03/16/2025 By admin

As a part of Postman Tutorial – End to End , in this post, we will learn “How to retrieve request body in Postman?”.

Verification is the purpose of testing. Suppose we need to create a booking and we pass required details like first name, last name, check in date, check out date etc. After booking we must need to verify if booking is done for passed data.

In Postman, we may require to fetch request data to assert with response data. For example:- Create Booking API requires a request body with below details like:-

{
     "firstname" : "Jim",
     "lastname" : "Brown",
     "totalprice" : 111,
     "depositpaid" : true,
     "bookingdates" : {
         "checkin" : "2020-01-01",
         "checkout" : "2021-01-01"
     },
     "additionalneeds" : "Breakfast"
 }

And after hitting, we get below Response:-

{
    "bookingid": 13,
    "booking": {
        "firstname": "Jim",
        "lastname": "Brown",
        "totalprice": 111,
        "depositpaid": true,
        "bookingdates": {
            "checkin": "2020-01-01",
            "checkout": "2021-01-01"
        },
        "additionalneeds": "Breakfast"
    }
}
 

Now we must cross verify details passed in request body are same as in response body.

We can get request JSON body in two ways:-

  1. var jsonReq = JSON.parse(pm.request.body.raw);
  2. var jsonReq1 = JSON.parse(request.data);

Now we can write json path to extract value and do all assertions.

Complete example is below:-

// "raw" gives string. So need to parse in to JSON
var jsonReq = JSON.parse(pm.request.body.raw);
var jsonRes = pm.response.json();


pm.test("Validate booking data with passed data in request body", function () {
    pm.expect(jsonReq.firstname).to.eql(jsonRes.booking.firstname);
    pm.expect(jsonReq.lastname).to.eql(jsonRes.booking.lastname);
    pm.expect(jsonReq.totalprice).to.eql(jsonRes.booking.totalprice);
    pm.expect(jsonReq.depositpaid).to.eql(jsonRes.booking.depositpaid);
    pm.expect(jsonReq.bookingdates.checkin).to.eql(jsonRes.booking.bookingdates.checkin);
    pm.expect(jsonReq.bookingdates.checkout).to.eql(jsonRes.booking.bookingdates.checkout);
    pm.expect(jsonReq.additionalneeds).to.eql(jsonRes.booking.additionalneeds);
});


// You can also get request body using below 
var jsonReq1 = JSON.parse(request.data);
console.log(jsonReq1.firstname)

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.

Uncategorized

Post navigation

Previous Post: api tutorials
Next Post: TestNG Tutorials 36: Can a Test Method Return a Value in TestNG?

Related Posts

Method 2: getCssValue() : What, When and How to use? Uncategorized
image – Make Selenium Easy Uncategorized
#5. OAuth 2.0 Flow – What Is A Refresh Token? Uncategorized
LeetCode Java Programs Uncategorized
July 16, 2019 – Make Selenium Easy Uncategorized
TestNG Tutorials 49: Need of DataProvider Method in TestNG | Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark