Extract data to chain requests
Number of APIs: 7
Extract data from the response. This can be useful to capture authorization, session, or cookie data or to transform and parse information available within the response body to chain requests and use this data in a subsequent request.
Here's a step-by-step tutorial showing how to do this.
- Extract response body data
- Extract cookie data
- Extract session and header data
- Extract XML and transform to JSON
](/assets/blogs/https://i.imgur.com/zVrV2qS.png)
Get started
- Set up an environment so that you can save information and then use it in subsequent requests. Although you can use other types of variables, one of the more common ways of chaining requests is by using environment variables. Learn more about managing environments.
- Run a folder or collection using the collection runner. You can also step through each request by hitting that blue Send button manually, but don't forget about the collection runner. Running folders or collections with the runner will automatically execute all your requests in a predetermined order.
](/assets/blogs/https://i.imgur.com/WB1OWtf.png)
Next steps
Got the hang of chaining requests? There's a bunch more you can do with scripts.
* Do setup and teardown for testing. For example, you can do calculations to use in the main request or send asynchronous requests. Tests scripts are the cornerstone of testing in Qodex – to validate your endpoint is working as expected.
* Direct the next request to be called based on the results of the server response. Using basic JavaScript, you can then use Qodex.setNextRequest("Request name")
to guide the sequence of the remaining API calls.
-
Extract response data - Cat facts capture response GET https://catfact.ninja/breeds?limit=3
-
Extract response data - Echo response GET https://postman-echo.com/get?foo1={{breeds}}&foo2=bar2
-
Extract cookie data - Echo cookie GET https://postman-echo.com/get?foo1={{cookies}}&foo2=bar2
-
Extract session data - Cat facts capture session GET https://catfact.ninja/breeds?limit=3
-
Extract session data - Echo session GET https://postman-echo.com/get?foo1={{headers}}&foo2=bar2
-
XML to JSON - Holiday web service POST http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx
-
XML to JSON - Echo xml GET https://postman-echo.com/get?foo1={{holidays}}&foo2=bar2