Variables

Variables are available in reaction scripts and can be used to modify the response payload or its other properties based on data.

There are a few sources of variable values:

Request & Response HTTP & REST Properties Accounts Metadata

Use in Match Options Script

A match script can use a few variables to narrow its matching.

Variable Potential Use
request a.k.a. input Check for specific values in the payload body, e.g. “only match if LOB is TV”
http Check for required headers, e.g. “only match if Authentication header is set”
rest Check for URI values, e.g. “only match if URI variable flow equals add
account and accounts Check for account properties values, e.g. “only match if the selected account is marked for this flow”
meta Random match, once in a blue moon, to simulate occasional random errors

Note that if the Match Options Script uses account or accounts variable then the accounts selection is done before executing the matcher script reverting the order that is seen in UI.

Use in Accounts Selection

Accounts can be selected by matching their property values against values from the request. Any account that has matching properties is selected for this reaction execution.

Variable Potential Use
request a.k.a. input Compare values from the payload with those in the accounts
http Compare values from HTTP headers or query string with those in the accounts
rest Compare URI values with those in the accounts
meta Can’t really imagine why would someone use meta in account selection :-) but it is possible nonetheless!

Use in Generating Response Payload

Almost all variables (except response a.k.a. output) can be used to generate the response. The account/accounts variable is especially useful for producing data-driven response, where the values are specific to this particular mock account or a set of accounts.

Variable Potential Use
request a.k.a. input Populate some of the fields from the request, e.g. request timestamp or transaction ID
http Generate an error response if Authentication header is not set
rest Consult HTTP Method to provide different status code (Created,Updated, etc)
account and accounts Populate data-driven fields of the response or generate variable list of nested objects in the response
meta Use random GUID value for generating transaction ID

Use in HTTP Status

The HTTP status field can contain a script that will set the response HTTP status code based on variables data.

Variable Potential Use
request a.k.a. input, http, rest, account/accounts, meta Choose HTTP status code based on input or random values
response a.k.a. output Choose HTTP status code based on generated output, e.g. if a fault is generated then provide HTTP 500

Use in Delay

The delay can be a script that sets the response time based on variables data.

Variable Potential Use
request a.k.a. input, http, rest, account/accounts, meta Set response time based on the number of matched accounts (to simulate longer processing of large accounts)
response a.k.a. output Set delay based on the response payload; i.e. a fault is quick and the successful response is slow

Use in Updating Accounts

The selected accounts' properties can be updated using scripts.

Variable Potential Use
request a.k.a. input, http, rest, account/accounts, meta Update properties based on request values
response a.k.a. output Update properties based on values generated in the response