Overview
Collection variables are reusable key-value pairs that can be referenced across all routes within a collection. They provide a centralized way to manage configuration values and secret references, ensuring consistency and reducing duplication.Variable Types
Value Variables
Standard variables that store plain-text configuration values like API endpoints, timeout settings, or feature flags. Example:Secret Variables
Variables that reference encrypted secrets stored in your KnoxCall vault. These are ideal for sensitive data like API keys, passwords, or tokens. Example:Creating Variables
Configure Variable
- Key: Enter a unique identifier (alphanumeric and underscores only)
- Type: Choose “Value” for plain text or “Secret” for sensitive data
- Value/Secret: Enter the value or select an existing secret
- Description: (Optional) Add notes about the variable’s purpose
Using Variables in Routes
Reference collection variables in your routes using the template syntax:Supported Fields
Collection variables can be used in:- Target URLs -
https://api.example.com/{{var:api_version}}/users - Headers -
Authorization: Bearer {{var:auth_token}} - Query Parameters -
?api_key={{var:api_key}} - Request Bodies - JSON values that reference variables
Example: Using Variables in a Route
Collection Variables:Variable Resolution
Priority Order
When a variable name appears in multiple places, KnoxCall resolves it in this order:- Environment-specific overrides (coming soon)
- Collection variables (current)
- Route-level variables (future feature)
Environment Context
When using Environment-Specific Secrets, collection variables automatically resolve to the correct environment’s secret value based on the active environment of the route. Example:- Variable
api_keyreferences secret “API Key” - Secret “API Key” has different values for
productionandstaging - When route is accessed in
productionenvironment → uses production API key - When route is accessed in
stagingenvironment → uses staging API key
Best Practices
Use Descriptive Keys
Use Descriptive Keys
Choose clear, self-documenting variable names like
stripe_webhook_secret instead of secret1Leverage Secret Variables for Credentials
Leverage Secret Variables for Credentials
Always use secret variables (not value variables) for API keys, passwords, tokens, and other sensitive data
Document Your Variables
Document Your Variables
Use the Description field to explain what each variable is for and how it should be used
Group Related Variables
Group Related Variables
Avoid Duplication
Avoid Duplication
If multiple collections need the same variable, consider if they should be merged into one collection
Common Use Cases
API Versioning
Multi-Tenant Configuration
Feature Flags
Environment-Specific Endpoints
Managing Variables
Editing Variables
- Navigate to the Variables tab in your collection
- Click on the variable row to open the editor
- Modify the value or description
- Click Update to save changes
Copying Variable References
- In the Variables tab, click the ⋯ menu for a variable
- Select Copy reference
- The variable syntax
{{var:key_name}}is copied to your clipboard
Deleting Variables
- Click the ⋯ menu for the variable
- Select Delete
- Confirm the deletion
Troubleshooting
Variable Not Resolving
Variable Not Resolving
Symptoms: Route shows
{{var:key_name}} in logs instead of the actual valueSolutions:- Verify the variable key is spelled correctly (case-sensitive)
- Check that the variable exists in the collection
- Ensure the route is assigned to the correct collection
Secret Variable Shows as Empty
Secret Variable Shows as Empty
Symptoms: Secret variable resolves to empty stringSolutions:
- Verify the secret exists and has a value
- Check that the secret is not deleted
- For environment-specific secrets, ensure the secret has a value for the active environment
Variable Key Validation Error
Variable Key Validation Error
Symptoms: Can’t create variable with certain charactersSolutions:
- Variable keys must be alphanumeric plus underscores only
- Use
api_keyinstead ofapi-keyorapi.key - Keys cannot start with a number
Next Steps
Environment-Specific Secrets
Learn how to use different secret values per environment
Collection Environment Defaults
Configure default settings per environment at the collection level