Dynamic Variables
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 variables are resolved at deploy time. They can have different values for environments such as development, test, and production.
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
| Feature | Environment Variable (${key}) | Context Variable (#{key}) |
|---|---|---|
| Format | ${variableName} | #{variableName} |
| Resolution Time | At deploy time | On each request |
| Value Source | Defined in Environment Variable management screen | Auto-generated by system or assigned via script |
| Environment Dependent | Yes — different values for dev, test, prod | No — per-request |
| Definition Requirement | Requires definition in Environment Variable screen | System variables: not required. Global variables: requires Custom Variable definition |
| Typical Usage | Host names, base URLs, ports, connection details | User information, request details, date/time, error details |
| Mutability | Fixed after deployment | Can vary on each request |
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}
2. Global Variables — Created via script, requires Custom Variable definition:
#{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:
https://${api.hostname}/v1/users/#{userId}
${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
| Policy | Supported Fields | Variable Types |
|---|---|---|
| REST API Call | URL, header, parameter, body | ${key} and #{key} |
| OIDC | Token endpoint, introspection endpoint, resource endpoint, form parameters | ${key} and #{key} |
| JOSE Validation / Implementation | Dynamic key HTTP endpoint | ${key} and #{key} |
| Authentication API | URL, header, parameter | ${key} and #{key} |
| Message Builder | Template, header, form fields | ${key} and #{key} |
| Redaction | Key-value list | ${key} and #{key} |
| Other policies | Text (string) input fields | ${key} and #{key} |
Script policy is not included in this table. The #{key} placeholder mechanism is not used in Script policy because variables are already accessed directly via the customVariableMap object and bindings such as request_httpMethod, dateTime_year. See Script Format Difference for details.
Connections
| Connection Type | Supported Fields |
|---|---|
| Database Connection | Host, port, username, password, connection string |
| LDAP Connection | URL, base DN, username, password |
| Email Connection | Host, port, username |
Other Fields
| Field | Supported Types |
|---|---|
| Routing Address | ${key} and #{key} |
| JSON Error Response Template | #{key} (including error variables) |
| XML Error Response Template | #{key} (including error variables) |
| Identity Provider (DB, LDAP, API) | ${key} and #{key} |
| IP Group | ${key} and #{key} |
| Credential | ${key} and #{key} |
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
Clicking a variable copies it to the clipboard in ${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
Clicking a variable copies it to the clipboard in #{variableName} format.
Both dialogs are independent. You can use both ${key} and #{key} in the same field.
Context Variable Reference
Request
| Format | Description | Example Value |
|---|---|---|
#{context.request.httpMethod} | HTTP method | GET, POST |
#{context.request.uri} | Request URI | /api/users/123 |
#{context.request.contentType} | Content type | application/json |
#{context.request.remoteAddress} | Client IP address | 192.168.1.100 |
#{context.request.queryString} | Query parameters | ?id=123 |
#{context.request.pathInfo} | Path information | /api/users |
#{context.request.contextPath} | Context path | /apinizer |
DateTime
System DateTime Variables
All context.system.* date/time variables return UTC values. To get time in a specific timezone or apply custom formatting, use the Date/Time Helper (dtf) function described below.
| Format | Description | Example Value |
|---|---|---|
#{context.system.year} | Year | 2026 |
#{context.system.month} | Month (1-12) | 2 |
#{context.system.dayOfMonth} | Day (1-31) | 4 |
#{context.system.dayOfWeek} | Day of week (1=Monday, 7=Sunday) | 3 |
#{context.system.hour} | Hour (0-23) | 14 |
#{context.system.minute} | Minute (0-59) | 30 |
#{context.system.second} | Second (0-59) | 45 |
#{context.system.epochMillis} | Unix timestamp (milliseconds) | 1707058245000 |
#{context.system.dateTime} | Formatted date/time (UTC) | 2026-02-04T14:30:45.000Z |
#{context.system.date} | Formatted date | 2026-02-04 |
#{context.system.time} | Formatted time | 14:30:45 |
Formatted date/time values are returned using these patterns:
- Date-time:
yyyy-MM-dd'T'HH:mm:ss.SSS'Z'→2026-02-04T14:30:45.000Z - Date:
yyyy-MM-dd→2026-02-04 - Time:
HH:mm:ss→14:30:45
The output time zone is determined by the Zone ID field in the variable definition.
Date/Time Helper (dtf)
The dtf JEXL helper function provides timezone-aware date/time formatting and is available in policy templates and custom error message templates (used in Message Builder and Business Rule Stop actions).
API Reference:
| Method | Description | Example |
|---|---|---|
dtf.format(zone) | Format using default pattern yyyy-MM-dd HH:mm:ss with specified timezone | #{dtf.format('+03:00')} → 2026-07-14 15:00:00 |
dtf.format(zone, pattern) | Format using custom pattern with specified timezone | #{dtf.format('+03:00','yyyy-MM-dd\'T\'HH:mm:ssXXX')} → 2026-07-14T11:57:13+03:00 |
dtf.epochMillis() | Get current Unix timestamp in milliseconds | #{dtf.epochMillis()} → 1740912645000 |
Zone Parameter:
The zone parameter accepts both timezone offsets and zone IDs:
- Offset format:
+03:00,UTC,-05:00 - Zone ID format:
Europe/Istanbul,America/New_York,Asia/Tokyo
Pattern Syntax:
Custom patterns follow Java SimpleDateFormat syntax. Common pattern letters:
yyyy— 4-digit yearMM— 2-digit monthdd— 2-digit dayHH— 2-digit hour (0-23)mm— 2-digit minutess— 2-digit secondXXX— timezone offset (e.g.,+03:00)T— literal "T" (must be escaped as\'T\'in JEXL string arguments)
In JEXL string arguments, the literal character T must be escaped with single quotes: \'T\'. Without this escape, the pattern parser will throw an "Unknown pattern letter" error. For example:
- Correct:
#{dtf.format('+03:00','yyyy-MM-dd\'T\'HH:mm:ssXXX')} - Incorrect:
#{dtf.format('+03:00','yyyy-MM-ddTHH:mm:ssXXX')}← Will fail
Comparison with System DateTime Variables:
| Feature | #{dateTime.formattedText} | #{dtf.format(...)} |
|---|---|---|
| Format | Fixed: yyyy-MM-dd HH:mm:ss | Custom patterns supported |
| Timezone | Always UTC | Timezone-aware and configurable |
| Flexibility | No — predefined output | Yes — full control over formatting |
Use system DateTime variables when you need simple, fixed-format output in UTC. Use dtf when you need timezone-specific or custom-formatted timestamps.