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.
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
- 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.
- API request 2 is “httpbin.org/post”
- Parametrize the orderId value in JSON body of Request 2.
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.