API Gateway 10.11 | Using API Gateway | Usage Scenarios | Custom Policy Extension | How Do I Define a Custom Variable?
 
How Do I Define a Custom Variable?
This use case explains how to define custom variable using custom extension. The defined custom variable can be used in any of the subsequent policy stages during API processing.
The use case starts when you have to define a custom variable, which is not available in API Gateway and ends when you successfully defined and accessed the variable in the subsequent policy stages.
*To define a custom variable using custom extension
1. Click APIs on the title navigation bar.
2. Click the required API.
The API details page appears.
3. Click Edit.
4. Select Policies.
5. Click Required Policy stage > Custom Extension.
This adds the custom extension policy where you can configure the required properties.
Click to open the policy properties section in a full page.
6. Provide the following information in the Conditions section, as required:
Property
Description
Condition
Conditions are used to specify when the policy has to be executed. You can add multiple conditions with logical operators.
Available values are:
*AND. API Gateway executes this policy when all the configured conditions comply in the respective policy stage.
*OR. This is selected by default. API Gateway executes this policy when any one of the configured conditions complies.
Click Add Condition and provide the following information and click Add.
*Variable. Specifies the variable type with a syntax.
*Operator. Specifies the operator to use to relate variable and the value. You can select one of the following:
*Equals
*Equals ignore case
*Not equals
*Not equals ignore case
*Contains
*Exists
*Range
*Greater Than
*Less Than
*Value. Specifies a plain value or value with a syntax.
For details about the variables available in API Gateway, see Variables Available in API Gateway.
7. Click Custom Variable.
8. Provide the following information in the Define Custom Variables section, as required:
Property
Description
Custom Variable
Specify the custom variable with a syntax to be accessed across subsequent stages and click Add.
*Variable. Specifies the custom variable with a syntax.
*Value. Specifies a plain value or value with a syntax.
For example, if you want to use the client's request related information like content-type header at response stage, you can define the ${clientContentType} custom variable to store the ${request.headers.Content-Type} variable. The ${clientContetType} custom variable can be accessed in any other policy across subsequent stages such as response or error processing stage.
For details about the variables available in API Gateway, see Variables Available in API Gateway.
9. Provide the following information in the Custom Extension Metadata section, as required. This is applicable only for XML transformation:
Property
Description
Namespace Prefix
Provide the namespace prefix of the payload expression to be validated.
For example, specify the namespace prefix as SOAP_ENV.
Namespace URI
Provide the namespace URI of the payload expression to be validated.
For example, specify the namespace URI as http://schemas.xmlsoap.org/soap/envelope/. This declaration defines SOAP_ENV as an alias for the namespace: http://schemas.xmlsoap.org/soap/envelope/.
Note:
You can add multiple namespace prefixes and URIs by clicking Add.
10. Click Save.
The API is saved with the added custom variables.
11. Invoke the API.
The custom variables are defined and can be accessed in the subsequent policy stages.