Supporting resources for the 2020 Postman Galaxy Tour bit.ly/postman-galaxy-workshop
< Previous section: Prepare for launch
Now that we’ve tried out collection runs, variables, and test snippets, let’s explore how to pass data between requests and change the order of execution.
Open the collection web documentation for future reference.
Test scripts let you pass data around in Postman, so you can chain tests together with shared data.
workshop
, click Add, and close the Manage Environments modal.workshop
environment you just created. With this selected, any requests we run will reference variables in this environment.Integration tests
folder > Using variables
sub-folder, send the request Bitcoin exchange rate
and inspect the response..set
method. It’s saving a var to the environment. Open the environment quick look—it should be in there now because we ran the request.Echo the exchange rate
. Notice that the URL references the bitcoinRate
variable set in the previous request tests. Send the request to see the response. The request used the value returned from the previous one.Your scripts can alter the flow of request execution when you use the collection runner.
API Learner
collection. Run the collection and notice the flow of execution. All four requests should run.GET data
and Send it. The response includes a field message
and a text string value.message
and set the next request by name (the conditional test should return true):let jsonData = pm.response.json();
let responseField = jsonData.message;
//check the length of the text
if (responseField.length > 10) {
//note - setnextrequest only works when you use collection runner
postman.setNextRequest("Put data");
}
null
to the setNextRequest
method:if (responseField.length > 10) {
postman.setNextRequest(null);
}
You can pass data between requests even if they are not in the same collection. Let’s try that using environments.
Integration Tests
> Bitcoin exchange rate
request again. In the Tests remember that it sets the bitcoinRate
environment variable. Make sure the workshop
environment is selected.POST data
request.{
"name": "sue",
"value": "{{bitcoinRate}}"
}
Variable scopes determine where variable values are available within Postman, as well as which one takes precedence if you different vars with the same name.
In this section we:
Shout out any questions you have on scripting request order, passing data around, setting variables from scripts, accessing variables in request body.
Go to kahoot.it and enter the pin shown on the screen—answer the questions as quick as you can to win an Amazon gift card!
Check out the docs:
And more templates you can try out in Postman:
Next up: Liftoff