Example to store data from the first response and feed it to the second request as a query param
We will make two GET requests in this example. The first request will return a JSON response in which each element contains an "id" key with values starting from 1. We will extract "id" value of the second element (so the extracted value is 2), store it in a variable named var, and use the variable as a query param in the second request.
Run API calls with the following data:
Request 1:
HTTP method: GET
Variables:
Source: JSON Body
Property: [1].id
Variable: var
Request 2:
HTTP method: GET
The following is a truncated view of the first response. The highlighted value of 'id' is what is extracted and supplied as a query param in the second request URL.
The following is the response of the second request, and you can see the second element from the previous response being returned. You can also see the variable value (2) in the second request URL.
Example using a global variable as base URL of the request
Supply the following values for the API request.
HTTP method: GET
URL: {{$baseurl}}users/
Run the test to view its response. You can also see the variable value inserted in the request URL.
- Variables