Chaining helps test how different parts of a system work together step-by-step, just like real users do.
Why chaining simulates real workflows in Postman
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
Postman
pm.sendRequest(request1, function (err, res1) {
// Use data from res1
pm.sendRequest(request2, function (err, res2) {
// Continue chaining as needed
});
});Each request waits for the previous one to finish before starting.
You can pass data from one response to the next request.
Examples
Postman
pm.sendRequest({ url: 'https://api.example.com/login', method: 'POST', body: { mode: 'raw', raw: JSON.stringify({ username: 'user', password: 'pass' }) } }, function (err, res) {
const token = res.json().token;
pm.sendRequest({ url: 'https://api.example.com/profile', method: 'GET', header: { Authorization: `Bearer ${token}` } }, function (err, res2) {
console.log(res2.json());
});
});Postman
pm.sendRequest({ url: 'https://api.example.com/items', method: 'POST', body: { mode: 'raw', raw: JSON.stringify({ name: 'item1' }) } }, function (err, res) {
const itemId = res.json().id;
pm.sendRequest({ url: `https://api.example.com/items/${itemId}`, method: 'DELETE' }, function (err, res2) {
console.log('Item deleted');
});
});Sample Program
This script creates a post, then fetches it using the returned ID, simulating a real workflow.
Postman
pm.sendRequest({
url: 'https://jsonplaceholder.typicode.com/posts',
method: 'POST',
header: { 'Content-Type': 'application/json' },
body: { mode: 'raw', raw: JSON.stringify({ title: 'foo', body: 'bar', userId: 1 }) }
}, function (err, res) {
if (err) {
console.error('Error creating post:', err);
return;
}
const postId = res.json().id;
console.log('Post created with ID:', postId);
pm.sendRequest({
url: `https://jsonplaceholder.typicode.com/posts/${postId}`,
method: 'GET'
}, function (err2, res2) {
if (err2) {
console.error('Error fetching post:', err2);
return;
}
console.log('Fetched post title:', res2.json().title);
});
});Important Notes
Chaining ensures tests follow the real order of actions users take.
It helps catch bugs that happen only when steps depend on each other.
Be careful with error handling to avoid silent failures in chains.
Summary
Chaining mimics real user workflows by linking requests step-by-step.
It passes data between requests to test connected actions.
This approach helps find issues in multi-step processes.
Practice
1. Why is chaining requests in Postman important for testing workflows?
easy
Solution
Step 1: Understand chaining concept
Chaining means connecting requests so output from one is input to another, like real user steps.Step 2: Identify why chaining matters
This simulates real workflows where actions depend on previous results, catching issues in multi-step processes.Final Answer:
It simulates real user actions by linking multiple requests step-by-step. -> Option BQuick Check:
Chaining = simulating workflows [OK]
Hint: Chaining links requests like real user steps [OK]
Common Mistakes:
- Thinking chaining runs requests in parallel
- Believing chaining auto-generates data
- Assuming chaining tests requests independently
2. Which Postman feature is used to pass data from one request to another in a chain?
easy
Solution
Step 1: Identify data passing method
Environment variables store data accessible across requests in a collection.Step 2: Understand chaining data flow
Data saved in environment variables from one request can be used in the next, enabling chaining.Final Answer:
Environment variables -> Option AQuick Check:
Data passing = Environment variables [OK]
Hint: Use environment variables to share data between requests [OK]
Common Mistakes:
- Confusing pre-request scripts with data storage
- Thinking collection runner passes data automatically
- Assuming response body alone passes data
3. Given this Postman test script snippet in Request 1:
And in Request 2 header:
What happens when these requests run in a chain?
pm.environment.set('token', pm.response.json().authToken);And in Request 2 header:
Authorization: Bearer {{token}}What happens when these requests run in a chain?
medium
Solution
Step 1: Analyze token setting in Request 1
Request 1 saves authToken from its response into environment variable 'token'.Step 2: Check usage in Request 2
Request 2 uses {{token}} in Authorization header, so it uses the saved token from Request 1.Final Answer:
Request 2 uses the token from Request 1's response for authorization. -> Option AQuick Check:
Token saved then used = Authorization works [OK]
Hint: Set variable in one request, use it in next [OK]
Common Mistakes:
- Assuming variables update after all requests run
- Thinking token is empty without manual setting
- Confusing order of request execution
4. You chained two requests in Postman, but the second request fails with a 401 Unauthorized error. What is the most likely cause?
medium
Solution
Step 1: Understand 401 error meaning
401 Unauthorized means missing or invalid authentication token in the second request.Step 2: Check chaining token setup
If the environment variable token was not set in the first request, the second request sends no valid token, causing failure.Final Answer:
The environment variable holding the token was not set correctly in the first request. -> Option DQuick Check:
401 error = missing token [OK]
Hint: Check token variable set before second request [OK]
Common Mistakes:
- Blaming URL without checking auth token
- Thinking collection runner affects token passing
- Ignoring first request response content
5. You want to test a multi-step user signup and login flow in Postman using chaining. Which approach best simulates this real workflow?
hard
Solution
Step 1: Understand multi-step flow
User signup creates a user ID needed for login authentication.Step 2: Apply chaining to pass data
Chaining saves user ID from signup response and uses it in login request to simulate real user flow.Final Answer:
Chain requests where signup saves user ID, then login uses that ID to authenticate. -> Option CQuick Check:
Chaining passes data to simulate workflow [OK]
Hint: Pass data stepwise to mimic user actions [OK]
Common Mistakes:
- Testing requests independently without data sharing
- Using hardcoded data ignoring dynamic flow
- Skipping login after signup
