DataPower API Gateway
only

Configuring the Set Variable policy for DataPower API Gateway

Follow these steps to configure the Set Variable policy for DataPower® API Gateway in the assembly user interface.

About this task

Note: This topic describes the Set Variable policy implementation in the DataPower API Gateway. If you are using the DataPower Gateway (v5 compatible), see Configuring the Set Variable policy for DataPower Gateway (v5 compatible). For more information about the different types of gateway, see API Connect gateway types.

For information about how to configure the policy in your OpenAPI source, see set-variable.

Procedure

  1. In the navigation pane, click Develop icon in the navigation pane Develop, then select the APIs tab.
    The Develop page opens.
  2. Click the title of the API that you want to work with, or create a new API.
  3. Select the Gateway tab, then click Policies in the navigation pane.
    For more information about working with the assembly editor for an API, see The assembly editor.
  4. Find the Set Variable policy in the palette, and drag the policy onto your canvas.
  5. Specify the following properties.
    Table 1. 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:
    • any
    • string
    • number
    • boolean

    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
  6. Specify a version for the policy by clicking the Source icon OpenAPI Source icon, and completing the version section of the policy YAML. For example:
    execute:
      - set-variable:
          version: 2.0.0
          title: set-variable
      ...
    You must specify a version for the policy that is compatible with the gateway that you are using. When the API is published, if the version is incompatible with the gateway, a validation error is thrown that specifies the available versions.
  7. Click Save.

Example

For examples, see set-variable.