Set Variable

Use the Set Variable policy to set the value of a runtime variable, or to clear a runtime variable, or to add a header variable.

Gateway support

Table 1. Table showing which gateways support this policy, and the corresponding policy version
Gateway Policy version
DataPower® Gateway (v5 compatible) 1.0.0
DataPower API Gateway, policy available from V2018.4.1.0 2.0.0

This topic describes how to configure the policy in the assembly user interface; for details on how to configure the policy in your OpenAPI source, see set-variable.

About

You can attach this policy to the following API flows:
  • REST
  • SOAP

Properties

The following table lists the policy properties, indicates whether a property is required, specifies the valid and default values for input, and specifies the data type of the values.

Table 2. Set Variable policy properties
Property label Required Description Data type
Title No The title of the policy.

The default value is set-variable.

string
Description No A description of the policy. string
Action Yes Defines what action to apply on a runtime variable.
Choose one of the following values:
  • Set: Indicates that you want to set a runtime variable to a string value. Can be used to set new headers or to override existing values.
  • Add: Indicates that you want to add a header variable. Can be used only to set new headers or to append a new entry of the same header name.
  • Clear: Indicates that you want to delete a runtime variable. Can be used to remove a header when the data is processed in the assembly flow.

The default value is Set.

string
Set, Add, or Clear Yes Specifies the name of the variable that you want to set , add or clear, depending on the selected Action. string
Type Yes Select the data type of the variable.
Choose one of the following values:
  • DataPower API Gateway
onlyany
  • string
  • number
  • boolean

If you are using the DataPower API Gateway then, for all values other than any, the value is validated against the specified data type.

string
Value Yes* Allocates this value to the specified variable. Can be a literal value, or another variable.

* Value is required only when Set or Add is specified as the action.

For example, to set a named variable of billing-hostname to a literal value, you can specify the Value as acme.com.

As another example, to set a named variable to the value of the Content-Type header in a request, you can specify the Value entry as $(request.headers.content-type).

If the selected value of the Type field is boolean, select the Value check box to indicated a value of true.

Note: You can only set single string elements. Values are retrieved as strings and therefore you cannot clone a complete nodeset.
string
For examples, see set-variable.