Inserting Data with Variables
Personalize your Courier notifications using variables from different data sources and insert them into various parts of a notification.
Read More: JSONPath Expressions
Data Sources for Substitution Variables
Courier enables you to use variables to insert dynamic values into your notifications from five sources:
The Data Object
The Data object is an optional property of the send command that allows you to pass arbitrary key-value pairs into your message template.
REFERENCING DATA OBJECT VARIABLES
Courier automatically references the data
path by default. You do not need to include data
in your variable path if the key-value pair is at the top level of the Data object. Nested values need to begin the path where the data value originates, e.g. {first_layer.second_layer}
VARIABLE NAMING CONVENTIONS
When using variables in your notification content, ensure that the variable names are in either camelCase or snake_case format. Using dashes or other unsupported characters in variable names will result in a rendering error.
- Valid variable name:
{firstName}
or{first_name}
- Invalid variable name:
{first-name}
The User Profile
User Profile data can be sourced from two places:
- The
profile
object in the Send API request. - The User Profile associated with the recipient ID, created via the Profiles API.
PRECEDENCE OF PROFILE DATA
If a conflict arises between the profile
object in the Send API request and the User Profile, the profile
object in the Send API request takes precedence.
Read More: JSON Paths and Variables Basics
Built-in Variables
Courier provides a set of predefined variables that are automatically populated with relevant data during the send process. These built-in variables can be used in your notification content and settings.
The available built-in variables include:
{courier.environment}
: The environment, e.g., “production” or “test”.{courier.scope}
: The notification scope, e.g., “published” or “draft”.{event}
: The event associated with the notification.{messageId}
: The unique identifier for the message.{openTrackingId}
: The tracking ID for email open events.{recipient}
: The recipient ID.{subscriptionTopicId}
: The ID of the subscription topic, if applicable.{template}
: The name of the template used for the notification.{unsubscribeTrackingId}
: The tracking ID for unsubscribe events.{urls.opened}
: The URL for tracking email opens.{urls.unsubscribe}
: The unsubscribe URL.{urls.preferences}
: The URL for managing the user’s notification preferences.{datetime.year}
: Load the current year in your notification.
Tenant Object
The Tenant object can be referenced to insert values specific to the tenant or organization, such as the tenant name.
Brand Object
The Brand object can be referenced to insert variables based on the active brand used in the notification. These variables can include brand names, colors, logos, or other branding elements.
Using Variables in Notifications
Variables can be used to insert data into:
- Notification content across all types
- Content Blocks (Text, Action, Markdown, Quote, Template, List)
- Handlebars code (Template blocks, Email templates, Brands)
- Email subject line and addresses (From, To, CC, BCC)
- Notification Conditions to control notification sending
- Channel Conditions to enable or disable specific channels
- Filters to conditionally show or hide content blocks
Example of Variable Replacement in Rendered Preview
The Notification Designer supports using external data in various places, such as:
Inserting Variables Into Content Blocks
To insert variables into Content Blocks, enclose the variable name within single curly brackets: {variable_name}
. Properly formatted variables inside Text, Markdown, Quote, and List Blocks will be highlighted in green.
Text Block With Variables
Inserting Variables into Handlebars
To insert data into Handlebars, use double curly brackets {{ }}
around the variable, following the same paths as in Content Blocks. However, you must include the Handlebars var
or path
helper to insert a variable from your JSON event:
- Data object:
{{var "variable_name"}}
- Profile data:
{{var "profile.variable_name"}}
Handlebars code is used in the Template Content Block type, Brand Templates, and the Handlebars override within Email Notifications.
Inserting Variables into Email Fields
In addition to the Handlebars Template override, variables are supported in the Subject
line, From
address, Reply-To
, CC
, and BCC
fields in the email channel settings.
Email Subject With Variables
Email Channel Settings