Overview
In Apinizer, dynamic variables can be used in many string fields such as policy settings, connection configurations, and routing addresses. This allows you to define values that change based on environment, request, or runtime instead of using fixed values. There are two types of dynamic variables:Environment Variable — ${key}
Environment variables are resolved at deploy time. They can have different values for environments such as development, test, and production.
Context Variable — #{key}
Context variables are resolved on each request. They contain system data such as request information, date/time, or custom values assigned via script.
Two Variable Types
Environment Variable (${key})
Environment Variables allow you to use different values across environments (development, test, production). They are resolved at deploy time and remain fixed during runtime.
Example: ${api.hostname} → localhost:8080 in development, api.example.com in production
For detailed information about Environment Variable definition and management, see the Environment Variable page. For CRUD operations and usage scenarios, see the Environment Variable Management page.
Context Variable (#{key})
Context Variables are resolved on each request and consist of two subcategories:
1. System Context Variables — Auto-generated, no definition required:
#{context.request.httpMethod},#{context.request.uri},#{context.request.remoteAddress}#{context.system.year},#{context.system.dateTime}#{context.message.correlationId}#{context.apiProxy.name},#{context.apiProxy.id}#{context.credential.clientId},#{context.credential.username}#{error.defaultErrorCode},#{error.defaultMessage}
#{userId},#{tenantId},#{customValue}- Values are assigned using
customVariableMap.put("key", "value")in Script policy
For detailed information about variable definitions, see the Variables page.
Mixed Usage
Both types can be used together:${api.hostname} is resolved at deploy time (e.g., api.example.com), while #{userId} gets a different value on each request.
Supported Fields
Dynamic variables can be used in nearly all string fields in policy and connection settings.Policies
Connections
Other Fields
In connection settings (Database, LDAP, Email),
${key} (Environment Variable) is typically used because these values are environment-specific and should be resolved at deploy time. #{key} (Context Variable) is resolved at request time and is more commonly used in policy settings and routing addresses.Variable Selection in UI
In policy and connection edit screens, a “Variable” button is available in the breadcrumb area. Clicking this button opens a menu providing access to two dialogs:Environment Variable Dialog
When “Environment Variable” is selected from the menu, the dialog lists all defined environment variables:- Global Variables — Variables valid across all environments
- Environment-Specific Variables — Variables defined for specific environments
${variableName} format, ready to be pasted into the relevant field.
Context Variable Dialog
When “Context Variable” is selected from the menu, the dialog lists all available context variables organized by category:- Error Variables — Error information
- Request Variables — Request information
- Message Variables — Message information
- API Variables — API Proxy information
- Credential Variables — Authenticated credential information
- DateTime Variables — Date/time information
#{variableName} format.
Both dialogs are independent. You can use both
${key} and #{key} in the same field.Context Variable Reference
Request
DateTime
All
context.system.* date/time variables return UTC values. To get time in a specific timezone, use dtf.format('+03:00') inside a JEXL expression in the Message Builder policy.Message
Custom message variables defined on API Proxy or Proxy Group are also displayed in this category.
API
Credential
Error
Script Format Difference
Context variables use a different format inside Script policy. The dot (.) separator used at runtime is replaced with underscore (_) in scripts:
Global Variable Usage
Global variables are created through Custom Variable definitions and assigned values via script. They are used for data transfer between policies.1
Create Variable Definition
Go to Project > Variables and create a new definition with Custom Variable type.
2
Assign Value via Script
In Script policy, assign a value using
customVariableMap.put("variableName", "value").3
Use the Variable
Use
#{variableName} format in other policies and settings.Usage Examples
Error Response Template
Dynamic Routing
${api.hostname} is resolved at deploy time, while #{tenantId} and #{context.request.pathInfo} are resolved on each request.
Response Header Addition
Behavior Rules
- Missing
#{key}values are replaced with empty string (""); no exception is thrown, a warning-level log is written - Missing
${key}values cannot be resolved and remain as-is - In Script policy, the custom variable map is accessed directly, so the
#{...}placeholder mechanism is not used there - Variable names are case-insensitive
Next Steps
Environment Variable
Learn about environment variables in detail
Variables
Learn about variable definitions
Script Policy
Variable usage in Script policy
Environment Variable Management
Environment Variable CRUD operations

