Reading about variables is one thing. Using them is another. Here are five exercises. Do them in order. Each one builds on the previous. By the end, you will have a fully variable-driven, data-tested, chained collection.
Create two environments — "Dev" and "Staging." Both should have these variables: baseUrl, authToken (empty), testUserId. Use https://jsonplaceholder.typicode.com as baseUrl for Dev. Use https://reqres.in/api as baseUrl for Staging. Switch between them and send a GET request to {{baseUrl}}/users/1. Verify it works in both.
Create "Dev" environment with baseUrl = https://jsonplaceholder.typicode.com
Create "Staging" environment with baseUrl = https://reqres.in/api
Add testUserId = 1 to both environments
Create a GET request: {{baseUrl}}/users/{{testUserId}}
Run with Dev selected — verify response from JSONPlaceholder
Switch to Staging — run again — verify response from Reqres
Both should return 200 with user data (different formats, but both work)
Create a POST request to https://jsonplaceholder.typicode.com/posts. In the pre-request script, generate a random title, a timestamp-based body, and a random userId (1-10). Use these variables in the request body. Run it three times and confirm each creates a unique post.
// Your pre-request script should look like this:
const titles = [
"Understanding API Testing",
"Why Automation Matters",
"Postman Tips and Tricks",
"Data-Driven Testing Guide",
"CI/CD Pipeline Basics"
];
const randomTitle = titles[Math.floor(Math.random() * titles.length)];
const randomUserId = Math.floor(Math.random() * 10) + 1;
pm.environment.set("postTitle", randomTitle);
pm.environment.set("postBody", `Created at ${new Date().toISOString()}`);
pm.environment.set("postUserId", randomUserId.toString());Build a 3-request chain using JSONPlaceholder:
Create a CSV file with 5 users from JSONPlaceholder (IDs 1-5). Include columns: userId, expectedName, expectedCompany. Set up a GET request to {{baseUrl}}/users/{{userId}} with tests that verify the name and company name. Run via Collection Runner with the CSV file.
userId,expectedName,expectedCompany
1,Leanne Graham,Romaguera-Crona
2,Ervin Howell,Deckow-Crist
3,Clementine Bauch,Romaguera-Jacobson
4,Patricia Lebsack,Robel-Corkery
5,Chelsey Dietrich,Keebler LLCCreate a JSON data file for testing post creation. Include both valid and invalid test cases. Run the collection and verify that valid cases return 201 and invalid cases are handled properly.
[
{
"testCase": "Valid post - normal",
"title": "Test Post 1",
"body": "This is a valid post body",
"userId": 1,
"expectedStatus": 201
},
{
"testCase": "Valid post - long title",
"title": "This is a very long title to test how the API handles longer strings in the title field",
"body": "Body content here",
"userId": 2,
"expectedStatus": 201
},
{
"testCase": "Valid post - special characters",
"title": "Post with <html> & special chars",
"body": "Body with \"quotes\" and slashes",
"userId": 3,
"expectedStatus": 201
}
]After completing all 5 exercises, export your collection and environments. Keep them as templates. Every new API project you test will follow the same patterns — environments, variables, chaining, data files. You just built your reusable testing toolkit.
Key Point: Practice all five exercises. Environment setup, dynamic scripts, chaining, CSV testing, JSON testing. These five patterns cover 90% of real-world API testing workflows.