Save, manage, overwrite and calculate data by assigning variables.

variable-flow-control-header

Overview

The Variable block acts as a container capturing and retaining data passed into your APIs, enabling you to acceess and reference those values at a later use within your routes.

Variables you set with this block are only accessible in the specific API/workflow you’re setting them in. For globabl variables which are accessible throughout your whole project visit Environment Variable.

Interface

Within the Variable action you can define 1 or more variables. Variables are computed from top to bottom so the 2nd variable can also reference the newly set variable value from the variable above.

Type

From left to right you can first define the type of the variable by clicking the icon in the input field under the label Name. Defining this type acts as validation and when the variable is computed, the action throws an error if the computed value is not the specified type.

Name

The name of the variable must consist only of the characters, numbers with the following special characters being allowed also: -, _ and +.

Operator

Clicking the icon within the Value input field lets you define the operator for the variable assignment. Each variable type has its own set of available operators, with the Operator Set being the default and being available for all types. Additional operators are:

Type Number

  • Plus: Current value of variable plus the specified new value
  • Minus: Current value of variable minus the specified new value

Type Text

  • Append: Current value of variable plus the specified new value added at the end
  • Prepend: Current value of variable minus the specified new value added at the front

Type Array

  • Append: Current value of variable plus the specified new value added at the end of the list
  • Prepend: Current value of variable minus the specified new value added at the front of the list

Value

The value of variable defines the expression that will be computed and assigned to the variable as defined by the operator.

Checkout our functions documentation to learn about all our powerful build-in functions and the language syntax that drives them.

Example

1

Situation

This example API is called whenever a new order is submitted. The data received by this endpoint contains customer and shipping information. We are interested in the Zip Code as we want to trigger automations based on that value for each other.

The API receives the following JSON when an order is submitted:

{
  "customer": {
    "email": "johndoe@example.com",
    "name": "John Doe"
  },
  "order": {
    "orderNumber": "12345",
    "shipment": {
      "shipmentNumber": "S123",
      "shippingAddress": {
        "city": "Anytown",
        "streetAddress": "123 Main St"
        "location": [
          {
            "zipcode": "90001"
          },
          {
            "state": "CA"
          }
        ],
    ...
}
2

Creating the variable

We can access the customer’s Zip Code at {{$body.order.shipment.shippingAddress.location[0].zipcode}} and use the Variable action block to store it:

3

Deploy

Now, our variable dropdown will show our new Zip Code variable under Flow variables:

This means, for the rest of the workflow we can use $var.zip-code to access the value of the Zip Code.

Utilizing variables has many advantages. They are simply shorter in terms of character length which makes it easier to work with them. Furthermore, in case the originial JSON syntax of the customer order changes, we only need to adjust the syntax of the variable block once, instead of changes all action blocks where the Zip Code value is used.

If you want to learn how to access variables from actions, API requests, events etc. visit Variables.