We use data from one response to make the next request work correctly. This helps test real workflows where one step depends on the last.
0
0
Using extracted data in next request in Postman
Introduction
When you log in and need the token for the next API call.
When you create a user and want to update or delete that same user next.
When you get a list of items and want to test details of one item.
When you test a multi-step process where each step needs info from before.
Syntax
Postman
// Extract data from response pm.environment.set("key", pm.response.json().field); // Use data in next request URL or body GET https://api.example.com/items/{{key}}
Use pm.environment.set or pm.variables.set to save data.
Use double curly braces {{key}} to insert saved data in next request.
Examples
This saves the token from login to use later.
Postman
// Extract token from login response pm.environment.set("authToken", pm.response.json().token);
This adds the saved token to the Authorization header.
Postman
// Use token in next request header
Authorization: Bearer {{authToken}}Saves the new user's ID for update or delete requests.
Postman
// Extract user ID from create user response pm.environment.set("userId", pm.response.json().id);
Uses the saved user ID in the URL to get user details.
Postman
GET https://api.example.com/users/{{userId}}Sample Program
This example shows how to save a token after login, then use it in the Authorization header for the next request. It also saves a user ID after creating a user, then uses that ID in the URL to get user details.
Postman
// 1. Login request test script const jsonData = pm.response.json(); pm.environment.set("authToken", jsonData.token); // 2. Next request uses token in header // In Headers tab: Authorization: Bearer {{authToken}} // 3. Create user request test script const userData = pm.response.json(); pm.environment.set("userId", userData.id); // 4. Get user details request URL // https://api.example.com/users/{{userId}}
OutputSuccess
Important Notes
Always check the response structure before extracting data.
Use environment or collection variables to keep data organized.
Clear variables if you want to avoid using old data in new tests.
Summary
Extract data from one response to use in the next request.
Use pm.environment.set to save and {{variable}} to use data.
This helps test real workflows where requests depend on each other.