Variable Definition
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
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Unique name of the variable |
| description | string | No | Description for the variable |
| type | EnumVariableType | Yes | Variable type. See Variable Types |
Note
namemust be unique within a project
Variable Types
Variables support the following types:
HEADER- Extract data from HTTP headersPARAMETER- 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 valuesCUSTOM- Custom variable defined with script
Variable Types and Required Fields
HEADER Type
Extract data from HTTP headers.
| Field | Type | Required | Description |
|---|---|---|---|
| type | string | Yes | Must be HEADER |
| headerName | string | Yes | Name of the HTTP header field in request or response message |
Example
{
"name": "apiKeyVariable",
"description": "Extracts API key from header",
"type": "HEADER",
"headerName": "X-API-Key"
}
PARAMETER Type
Extract data from URL parameters (query, path, or form).
| Field | Type | Required | Description |
|---|---|---|---|
| type | string | Yes | Must be PARAMETER |
| paramType | string | Yes | Parameter type. See EnumVariableParameterType |
| paramName | string | Yes | Name of the parameter in request message |
| paramPath | string | Yes* | Template path to use for "path" parameter (required if paramType=PATH) |
| formName | string | No | Form field name (optional, used if paramType=FORM and differs from paramName) |
Note
- For
paramType=QUERY: UseparamNameonly - For
paramType=PATH: UseparamNameandparamPath(required) - For
paramType=FORM: UseparamName(required),formNameis optional and typically same asparamNameunless 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
{
"name": "userIdFromQuery",
"description": "Extracts user ID from query parameter",
"type": "PARAMETER",
"paramType": "QUERY",
"paramName": "userId"
}
Example 2: Path Parameter
{
"name": "orderIdFromPath",
"description": "Extracts order ID from path",
"type": "PARAMETER",
"paramType": "PATH",
"paramName": "orderId",
"paramPath": "/orders/{orderId}"
}
Example 3: Form Parameter
{
"name": "usernameFromForm",
"description": "Extracts username from form data",
"type": "PARAMETER",
"paramType": "FORM",
"paramName": "username",
"formName": "username"
}