Extracting Data From Responses and Chaining Requests

How To Extract Data From Responses Chaining Requests

In the previous articles on Postman Tutorial, we have covered “Generate Random/Dynamic Data in Requests” 

In this “Extracting Data From Responses and Chaining Requests” article, I will be demonstrating how you can extract data from responses and chaining requests in postman. This article helps you in implementing this concept and get a tight grip over this.

We can pass information from one request to the other by using variables and in this way, we can make our request more dynamic.

Let’s suppose that the value of one of the fields in the body of a request is to change with every request that we are sending and we need to go to another endpoint to get the value from response to use in our other request. We do this by using variables.

Postman Extract Data From Response

We save a variable in the Tests tab. Everything inside the Tests tab will be executed after the request completed so we have access to the response body. Let’s understand this with an example.

  • API request 1 is “httpbin.org/uuid”
  • Response generated is “uuid” : efdsg-75gsn-4dfe-54fgvdfg”
  • We need to fetch uuid value from response and send in Request 2

Postman Extracting Data

  • Under Tests tab of API request 1,

// access the response body

const response = pm.response.json();

//Saved as a global variable. Other requests can access this info as well.

pm.globals.set(“orderId”, response.uuid);

Postman Extracting Data

  • API request 2 is “httpbin.org/post”
  • Parametrize the orderId value in JSON body of Request 2.

Postman Extracting Data

Next steps:

Learn “Testing OAuth2 authorization in Postman” in the next tutorial.

Author Bio: This article is written by Harsha Mittal an ISTQB-CTFL Certified Software Test Engineer having 3.5+ years of experience in Software Testing.

Related posts:

Sharing is caring.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

Like This Post?

We have a lot more where that came from?

We only send really good stuff occasionally, promise.

Rajkumar SM

Leave a Comment

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

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on whatsapp

Recent Posts:

Scroll to Top
API Testing eBook

DOWNLOAD FOR FREE