Skip to main content
Define Variable Node

The Define Variable Node lets you create custom variable with incoming data payloads using Shopify's Liquid Template Language

Updated this week

What is this new node for?

The Define Variable node is a powerful new feature that lets you manipulate flow data in a much more flexible way than previously possible. Using the Liquid template language, you can modify or combine multiple existing variables (e.g. coming from a trigger) into new ones. For concrete examples and use cases, please read the section below.

Creating & configuring the Define Variable Node

To create a Define Variable Node, open the context menu and select "Define Variable". Similar to how the Condition Node lets you define 1-many rules, the Define Variable node lets you define 1-many variables.

First, give your Variables a name. This name lets you identify them easily later when you want to access them in message or webhook nodes. Next, click on "Add variable".

In the modal that appears, you can now type your Liquid code expression.

Once you hit save, we validate your Liquid code and display any syntax errors your code might have. If there are none, you are good to go 🀩.

πŸ€“ We know this is a feature for power users, so if you need assistance with writing your Liquid code, please refer to the official documentation here, or contact your Customer Success manager. They are happy to help you ☺️

You can define an arbitrary amount of variables. If you want to remove one, simply click the trash bin icon in the gray box of the variable.

⚠️ The defined variables are only accessible in the scope of the flow in which they are created. If you want to persist them, please use the "Update contact" node to store it on a customer profile or use an outgoing webhook to send them to a third-party system.

Data sources

Data source

Prefix

Example

Contact system properties

flowbuilder_trigger_person

To retrieve the first_name:
​
​flowbuilder_trigger_person.first_name

Contact custom properties

flowbuilder_custom_properties

flowbuilder_custom_properties.dog_name

Incoming webhook trigger

REST_TRIGGER.

Payload in the incoming webhook trigger:
​

{
"products": [
{
"title": "Oryx and Crake (The MaddAddam Trilogy)",
"image_url": "https://amazon.com"
}
]

}


Accessing the title:
​
​{{ REST_TRIGGER.products[0].title }}

Emarsys trigger

EMARSYS_TRIGGER.

Payload in the incoming webhook trigger:
​

{
"products": [
{
"title": "Oryx and Crake (The MaddAddam Trilogy)",
"image_url": "https://amazon.com"
}
]

}


Accessing the title:
​
​{{ EMARSYS_TRIGGER.products[0].title }}

Braze trigger

BRAZE_TRIGGER.

{{ BRAZE_TRIGGER.products[0].title }}

Examples & Use Cases

Now, let's look at some real-life examples to showcase the capabilities of this node type.

Accessing data in an array

If a flow is triggered by a custom event from an integration (e.g. Emarsys) or via the "Incoming Webhook Trigger", then you might need to access data from an array.

In the example below, we want to dynamically insert the product name and image URL into a message.

This is the event payload that triggers the flow:

{
"contact_id": 123456789,
"products": [
{
"item_id": "6",
"event_time": {
"value": "2019-08-15T07:44:16.000Z"
},
"new_price": 15,
"last_seen": {
"value": "2019-06-11T10:43:58.000Z"
},
"title": "Oryx and Crake (The MaddAddam Trilogy)",
"image_url": "https://images-na.ssl-images-amazon.com/images/I/51mwR1ZxtWL._SX322_BO1,204,203,200_.jpg",
"link": "https://www.amazon.com/Crake-MaddAddam-Trilogy-Margaret-Atwood/dp/0385721676",
"msrp": 25
}
],
"customer_id": 1234,
"criterion_id": "5d287aa67d13c400049655b9"
}

To extract the data, we can use the following liquid JS code

Image URL:

{{ event.products[0].image_url }}

Product name:

{{ event.products[0].title }}

Fetching Product Details

In some cases, events only contain the product ID and lack more meta data, such as the product URL, the image, or the name. For these cases, the Define Variable node provides the handy function get_product: '<id>' to pull this meta data by ID.

See the following two examples of how you can list the products with name and price or how you can fetch the image URL.

{%- for id in REST_TRIGGER.emarsys_product_id -%} 
{% assign product = id | get_product: 'id' %}
- {{ product.name }}: {{ product.price }}{{ product.currency }}
{%- endfor -%}
{% assign product = REST_TRIGGER.emarsys_product_id[0] | get_product: 'id' %} {{ product.assets_gallery_image_url[0] }}

Did this answer your question?