Skip to main content

Collection Variables

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:
When a route uses this variable, KnoxCall automatically resolves the secret value from the vault.

Creating Variables

1

Navigate to Collection

Open your collection and go to the Variables tab
2

Add Variable

Click the + button in the Variables card header
3

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
4

Save

Click Create to save the variable

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:
Route Configuration:
When a request is proxied, KnoxCall resolves:

Variable Resolution

Priority Order

When a variable name appears in multiple places, KnoxCall resolves it in this order:
  1. Environment-specific overrides (coming soon)
  2. Collection variables (current)
  3. 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_key references secret “API Key”
  • Secret “API Key” has different values for production and staging
  • When route is accessed in production environment → uses production API key
  • When route is accessed in staging environment → uses staging API key

Best Practices

Choose clear, self-documenting variable names like stripe_webhook_secret instead of secret1
Always use secret variables (not value variables) for API keys, passwords, tokens, and other sensitive data
Use the Description field to explain what each variable is for and how it should be used
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

  1. Navigate to the Variables tab in your collection
  2. Click on the variable row to open the editor
  3. Modify the value or description
  4. Click Update to save changes

Copying Variable References

  1. In the Variables tab, click the menu for a variable
  2. Select Copy reference
  3. The variable syntax {{var:key_name}} is copied to your clipboard

Deleting Variables

Deleting a variable will break any routes that reference it. Always verify usage before deletion.
  1. Click the menu for the variable
  2. Select Delete
  3. Confirm the deletion

Troubleshooting

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
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
Symptoms: Can’t create variable with certain charactersSolutions:
  • Variable keys must be alphanumeric plus underscores only
  • Use api_key instead of api-key or api.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