if

Use the if construct to apply a section of the assembly when a condition is fulfilled.

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, functionality provided by switch  

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 if.

An if construct provides a way to branch an API's assembly when a specified condition is fulfilled. Each if construct contains a section of the assembly that is only executed when the script within the construct returns a true value.

When using the assemble view's property sheet, use the Condition field to write your condition that returns true or false.

If you want one or more policies or constructs to be executed when the condition of the if construct is fulfilled, drag the new policy or construct onto one of the dashed boxes that are displayed within the if construct. Constructs and policies included in the if construct are part of the case that is executed when the condition of the if construct is returned as true.

For information about the OpenAPI implementation of an if construct, see if.

In the Condition field, use the form apim.getvariable('context.location.variable') to reference your variables, where context is the context that you want to reference, location is the location of the variable within that context, and variable is the name of the variable.

Construct property details

You can configure a construct's properties in the property sheet in the assemble view.

Table 2. The properties of an if construct
Property Required Description
Title No A custom title for your construct when it is displayed in the canvas. If a title is not specified, if is used by default.
Description No A description of your construct, it is not displayed on the canvas.
Condition Yes Use GatewayScript to provide conditions. A list of context variables that you can use to generate conditions can be found in API Connect context variables.