Skip to main content

Overview

Variable is a structure used to extract data from API traffic messages for policy needs. It is used to extract data from different parts of HTTP requests (header, parameter, body, etc.). Variables are used in policies, conditions, and other API configurations to dynamically access request/response data.

Basic Properties

Note

  • name must be unique within a project

Variable Types

Variables support the following types:
  • HEADER - Extract data from HTTP headers
  • PARAMETER - Extract data from URL parameters (query, path, form)
  • BODY - Extract data from request/response body (XML, JSON, or raw body)
  • CONTEXT_VALUES - Extract data from system context values
  • CUSTOM - Custom variable defined with script

Variable Types and Required Fields

HEADER Type

Extract data from HTTP headers.

Example

PARAMETER Type

Extract data from URL parameters (query, path, or form).

Note

  • For paramType=QUERY: Use paramName only
  • For paramType=PATH: Use paramName and paramPath (required)
  • For paramType=FORM: Use paramName (required), formName is optional and typically same as paramName unless you need a different field name

EnumVariableParameterType (paramType)

  • QUERY - Query parameter (e.g., ?userId=123)
  • PATH - Path parameter (e.g., /users/{userId})
  • FORM - Form parameter (form data)
Example 1: Query Parameter
Example 2: Path Parameter
Example 3: Form Parameter

BODY Type

Extract data from request/response body (XML, JSON, or raw body).

EnumMessageContentType (messageContentType)

  • XML - XML content type
  • JSON - JSON content type
  • ALL_BODY - Raw body content (all body)
Example 1: XML Body
Example 2: JSON Body
Example 3: All Body

CONTEXT_VALUES Type

Extract data from system context values.

Example

CUSTOM Type

Custom variable defined with script.

Note

  • If initWithScript is true, both scriptLanguage and scriptBody must be provided
  • If initWithScript is false (default), script fields are optional

Example

EnumVariableContextValue

Context values available for CONTEXT_VALUES type variables.

Request Status Information

API Proxy Group/Proxy/Method Values

Note: Date/time context values require zoneId field to be specified.

Credential Values

Complete Variable Examples

Example 1: Header Variable

Example 2: Query Parameter Variable

Example 3: Path Parameter Variable

Example 4: XML Body Variable

Example 5: JSON Body Variable

Example 6: Context Variable (Client IP)

Example 7: Context Variable (Date/Time)

Example 8: Custom Variable

Usage in Policies

Variables are used in various policies:
  • API Based Throttling - targetVariableForIdentity to identify clients
  • RLCL - targetVariable for rate limiting
  • Conditions - firstVariable and secondVariable for condition rules
  • Content Filter - Variables to filter content
  • Redaction - Variables to identify data to redact
  • Encryption/Decryption - Variables for source and target data

Notes and Warnings

  • Variable Names:
    • Variable names must be unique within a project
    • Use descriptive names for better understanding
  • Required Fields:
    • Each variable type has specific required fields
    • Missing required fields will cause validation errors
  • Context Values:
    • Date/time context values require zoneId field
    • Use IANA time zone identifiers (e.g., “Europe/Istanbul”, “America/New_York”)
  • XPath/JsonPath:
    • XPath expressions are used for XML content
    • JsonPath expressions are used for JSON content
    • Ensure expressions are valid for the content type
  • Custom Scripts:
    • Custom variables use scripts to extract data
    • Script language must be specified
    • Scripts have access to request/response objects