Manage Variables & Datasets
API Environment Variables and Datasets in E2E
API Environment Variables in E2E test automation (E2E) let you define and manage configuration values at the API collection level. These variables simplify switching between Development, Staging, and Production environments while ensuring consistency across requests.
E2E also introduces Datasets for environment variables. Datasets let you maintain multiple sets of values for the same variables, so you don’t need to create a new variable every time values change. Simply switch datasets to test different scenarios without editing individual requests.
What Are API Environment Variables at the Collection Level?
Environment variables are key-value pairs referenced across an entire API collection. Examples include:
- Base URLs:
https://dev.api.myshop.com - Auth Tokens:
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... - Session IDs:
session_8923_abcd - Custom Headers:
X-Client-ID: web-frontend-01
Key Advantages
- Centralized Configuration: Define once, reuse everywhere.
- Environment Switching: Move from Development to Production seamlessly.
- Consistency: Eliminate manual edits for every request.
How Environment Variables and Datasets Work Together
1. Define Environment Variables
Example variables at the collection level:
base_url = https://dev.api.myshop.com
access_token = Bearer dev_token_87963
session_cookie = session_dev_1252. Add Datasets for Variables
Instead of creating new variables for every change, E2E lets you define datasets for the same set of variables.
Switch datasets anytime to change test data instantly without touching the requests.
Using Environment Variables and Datasets in Requests
- Select Environment: Choose Development, Staging, or Production.
- Select Dataset: From the Dataset dropdown, pick the dataset (Default, LoadTest, Regression).
- Use
{{ }}Notation in Requests
Example 1: API URL with Dataset Variables
GET {\{base_url\}}/v1/users?limit=10- Default Dataset →
https://dev.api.myshop.com/v1/users?limit=10 - Production Dataset →
https://api.myshop.com/v1/users?limit=10
Example 2: Auth Headers
Authorization: {\{access_token\}}
Content-Type: application/json- Staging Dataset →
Authorization: Bearer staging_token_99123
Example 3: Request Body with Dynamic Session ID
{
"user_id": "user_98431",
"session": "{\{session_cookie\}}"
}- LoadTest Dataset →
"session": "session_staging_490"
Realistic Use Cases for Datasets
1. Testing Across Multiple Environments
- Default Dataset → Dev base URL + dev token
- Production Dataset → Prod base URL + prod token
GET {\{base_url\}}/v1/orders2. Regression Testing
- Dataset A → Old API version (
v1) - Dataset B → New API version (
v2)
GET {\{base_url\}}/{\{api_version\}}/orders3. Load Testing with Bulk Users
- Dataset 1 → 10 users
- Dataset 2 → 500 users
user_ids = [ "user_101", "user_102", "user_103" ]4. Negative Testing
- Dataset with expired tokens
- Dataset with missing headers
- Dataset with malformed session IDs
Authorization: Bearer expired_token_123455. A/B Testing Feature Flags
- Dataset A → Feature ON
- Dataset B → Feature OFF
{
"user_id": "user_451",
"feature_new_checkout": "{\{feature_new_checkout\}}"
}6. Regional API Testing
- Dataset EU →
https://eu.api.myshop.com - Dataset US →
https://us.api.myshop.com - Dataset Asia →
https://asia.api.myshop.com
GET {\{base_url\}}/v1/shipping-rates7. Error Reproduction from Production Logs
Create datasets with failing user IDs or invalid payloads for debugging:
{
"user_id": "user_error_901",
"cart_items": []
}Benefits of Environment Variables with Datasets
- Centralized Control: All configurations in one place
- Scenario Flexibility: Change datasets, not code
- Consistent Testing: Avoid copy-paste errors
- CI/CD Ready: Run collections with datasets in pipelines
- Broad Test Coverage: Positive, negative, and performance testing
- Faster Debugging: Switch to error datasets instantly
Conclusion
With Environment Variables and Datasets in E2E test automation (E2E):
- Environments manage Development, Staging, and Production settings
- Datasets enable quick value changes for multiple scenarios without creating new variables
This combination enables data-driven testing, improves test coverage, and eliminates repetitive work—making API testing scalable, efficient, and production-ready. 🚀