Variables
Variables allow you to reuse values across multiple requests and switch between different environments (development, staging, production) with ease.
What are Variables?
Variables are placeholder values that you can reference in your requests using the {{variable_name}} syntax. When you send a request, Roster automatically replaces these placeholders with the actual values from your selected environment.
Example:
URL: {{base_url}}/users
Headers:
Authorization: Bearer {{api_token}}
When sent with the "Production" environment:
URL: https://api.example.com/users
Headers:
Authorization: Bearer prod-token-abc123
Environments
Environments are collections of variable values. Common environment names:
- Production - Live API credentials
- Staging - Pre-production testing
- Development - Local development server
Each project can have multiple environments, and each environment has its own set of variable values.
Creating Environments
Step 1: Open Environments Dialog
- Select a project from the sidebar
- Click the "Three-Dots" button near the project name
- Select "Manage Environments"
Step 2: Add Environment
- Click + button near Environments
- Enter name (e.g., "Production", "Development")
- Click "Add"
The environment appears as a new column in the table.
Step 3: Add Variables
- Click the "+" button at the bottom of the variable list
- Enter variable name (e.g.,
base_url) - Click "Add"
The variable appears as a new row in the table.
Step 4: Set Values
Click in the cells to enter values for each environment:
| Variable | Production | Development |
|---|---|---|
| base_url | https://api.example.com |
http://localhost:3000 |
| timeout | 30 |
60 |
Close Manage Environments table to save.
Using Variables in Requests
Variable Syntax
Use double curly braces: {{variable_name}}
Variables work in:
- URL:
{{base_url}}/users - Headers:
Authorization: Bearer {{token}} - Request Body:
{"api_key": "{{api_key}}"}
Select Environment
- Open a request tab
- Use the environment dropdown (top of request panel)
- Select environment (e.g., "Production")
- All variables in the request will use values from this environment
Visual Indicators
Defined variables - Normal appearance
Undefined variables - Highlighted with a warning color
- Variable name exists in
{{...}}syntax - But not defined in current environment
Managing Variables
Rename Variable
- Open Manage Environments dialog
- Click on variable name
- Edit the name
The variable is renamed across all environments automatically.
Delete Variable
- Open Environments dialog
- Click the x next to variable name
- Confirm deletion
The variable is removed from all environments.
Rename Environment
- Open Environments dialog
- Click the edit icon on environment column header
- Enter new name
- Click "Save"
Delete Environment
- Open Environments dialog
- Click the trash icon on environment column header
- Confirm deletion
All variable values for that environment are deleted.
Note: Each project must have at least one environment.
Common Variable Patterns
Common variables to define across environments:
base_url- API base URL (e.g.,https://api.example.comvshttp://localhost:3000)api_version- API version (e.g.,v2vsv2-beta)timeout- Request timeout valuesenv- Environment identifier for headerstest_user_id- Test data IDs
Script Integration
Variables can be accessed and modified from Scripts:
Reading Variables (Preprocessing)
const baseUrl = roster.getVariable('base_url');
const apiKey = roster.getVariable('api_key');
console.log('Using base URL:', baseUrl);
request.headers['X-API-Key'] = apiKey;
Writing Variables (Postprocessing)
// Extract token from response and save for next request
const data = JSON.parse(response.body);
roster.setVariable('auth_token', data.access_token);
roster.setVariable('user_id', data.user_id);
console.log('Saved token for user:', data.user_id);
Batch Updates
// Update multiple variables at once
roster.setVariables({
access_token: data.access_token,
refresh_token: data.refresh_token,
user_id: data.user.id,
user_name: data.user.name
});
Scripts automatically update variables in the currently selected environment.
Variable Scoping
Project Level:
- Variables are defined at the project level
- All requests in the project can access these variables
Environment Level:
- Variable values are specific to each environment
- Switching environments switches all values at once
Not Global:
- Variables from one project cannot be used in another project
- Each project has its own isolated set of variables
Best Practices
- Keep environments consistent - All environments should have the same variable names with different values
- Use sensitive variables for secrets - Never store API keys, passwords, or tokens in regular variables (they're plain text). Use Sensitive-Variables instead
Undefined Variables
When {{variable_name}} is not defined in the current environment:
- Entry field is highlighted with warning color
- The literal text
{{variable_name}}is sent in the request
To fix, add the variable in the Environments dialog.
Environment Switching
Use the environment dropdown to test the same request against different targets. For example, GET {{base_url}}/users will hit localhost:3000/users in Development or api.example.com/users in Production.
Advanced Topics
- Variables in JSON body - Use
{{variable}}syntax. Remove quotes for numeric values - Nested variables - Variables can reference other variables (e.g.,
{{base_url}}/{{api_version}}) - Script-created variables - Scripts can create variables with
roster.setVariable()
Next Steps
- Sensitive-Variables - Store API keys and secrets securely
- Scripts - Automate variable management with JavaScript
- API-Reference - Complete API for working with variables