set-variable

Use the set-variable policy to set the value of a runtime variable, or to add or clear a runtime 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 your OpenAPI source; for details on how to configure the policy in the assembly user interface, see Set Variable.

About

The set-variable policy has the following format:
- set-variable:
  version: version
  title: title
  description: description
  actions:
    - action_type: variable_name
      value: value
      type: data_type

Properties

Table 2. set-variable policy properties
Property Required Description Data type
version Yes The policy version number string
title No A title for the policy. string
description No A policy description. string
actions Yes Lists the actions to be performed by the set-variable policy. array
set Yes1 For setting a variable. specifies the name of the variable that you want to set.

1One of the properties set, add, or clear is required.

string
add Yes2 For adding a variable. specifies the name of the variable that you want to add.

2One of the properties set, add, or clear is required.

string
clear Yes3 For clearing a variable. specifies the name of the variable that you want to clear.

3One of the properties set, add, or clear is required.

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

4value is required only when set or add is specified as the action.

string
DataPower API Gateway
onlytype Yes Specifies the data type of the variable.
Valid values:
  • any
  • string
  • number
  • boolean

For all values other than any, the value is validated against the specified data type.

If the data type is specified as boolean, the value property must be set to true or false.

string

Example 1

# clear a variable

set-variable:
  version: 1.0.0
  title: clear_region
  actions:
    - clear: message.headers.region

Example 2

# set a variable to the value of an API Gateway context variable

set-variable:
  version: 2.0.0
  title: set content type
  actions:
    - set: message.headers.contenttype
      value: $(message.headers.content-type)
      type: string

Example 3

# add a variable

assembly:
    execute:
      - set-variable:
          version: 2.0.0
          title: set-variable
          actions:
            - value: testing add
              add: message.headers.jja
              type: string