A Data Connection holds content you keep outside your templates — offers per loyalty tier, recommendations per customer, a live answer from your own API. To use it in a message, your template needs the Liquid that looks up the right row for each customer, and writing that by hand is slow, and a small typo breaks it.
The Data Connection Lookup writes it for you. You choose the connection, what to look up, which properties to return and what happens when there is no data, and it inserts finished Liquid at your cursor. You can see exactly what will be inserted before you insert it.
This guide will walk you through how to add a Data Connection lookup to a template, from opening the lookup to inserting the Liquid, and how to read what it writes.
How to Add a Data Connection Lookup to a Template
Open the Data Connection Lookup
You reach the lookup from the Personalization Picker, or from the menu beside a short text field.
- Open your Liquid template or content block and place your cursor where the content should go.
- Open the Personalization Picker: in the visual editor, click Personalization in the formatting toolbar; in the HTML editor, right-click and select Personalizations. For more, see How to Personalize Content with the Personalization Picker.
- Click Data Connection Lookup at the bottom of the Picker.
- In an SMS or push text field, click the ⋯ (More actions) menu for the field and select Data Connection instead.
Select a Data Connection
Each connection in the list shows its name, the first eight characters of its ID and a badge for its type: Upload for a file you uploaded, API for a connection that calls an API, including one created from a placement.
- Click the Data connection dropdown.
- Type in the box to search by name or ID.
- Select the connection. The rest of the form appears below it.
Choose Properties from an Upload Connection
Follow this step for an Upload connection. For an API connection, go to Step 4.
- In Property, select the column or columns you want to use. They're kept in the file's column order. The primary key column isn't offered, because it's what you look up by.
- Click the expand icon beside it to check the data. Sample of Rows shows the first five rows, with the primary key first.
- Under Look up, the greyed box shows the connection's primary key. In the dropdown beside it, select the customer attribute that holds the same value for each customer, for example CustomerID.
- To use something that isn't in the list, type any Liquid into the search and select Use custom liquid '…'.
Set Up an API Connection
For an API connection, the top of the form shows the method and URL it calls, with any credentials masked. A yellow warning here means the connection is set up wrongly, for example when the primary key isn't in the request. A connection's request can't be edited, so create a corrected connection and use that one.
- Under Look up, select the customer attribute that fills the connection's primary key.
- Under Parameters, select a Value for each placeholder: a customer attribute, or any Liquid you type. To send a fixed value, type it in single quotes, for example
'en'. - Check that each row has a Test value. Test values are sample inputs for the next step only; they're never written into your template.
- Click Fetch fields. When the API answers, a green tick appears and Property lists every field it returned, with its type. Nested fields appear as paths, for example
current.temp_C. To fetch again with other test values, click Fetch fields again. - In Property, select the field or fields you want to use.
Choose a Fallback Value
Decide what happens when there is no data for a customer.
- Under Fallback value, select one option:
- None — nothing is shown in place of the value. This is the default.
- Use default — type the text to show instead in Custom default value.
- Drop customer — the customer doesn't receive the message. A Drop reason is filled in for you; you can change it.
Choose the Output
Decide whether the value appears right where your cursor is, or is stored for use further down the template.
- Under Output, select one option:
- Render result directly — the value appears where your cursor is.
- Assign result to a variable — the result is stored under a variable name, suggested from the connection's name. You can change it.
Preview and Insert the Liquid
- Click Preview to see the Liquid in Liquid Preview. Long Liquid runs past the edge of the box; click Copy to get all of it.
- Click Insert. The Liquid is added at your cursor.
How the Data Connection Lookup Works
Everything the lookup inserts is plain Liquid, so you can read it, edit it, or copy it into another template. Each lookup names the connection by its ID, then the lookup value, then any API parameters, then the properties to return. Here is what it writes for a connection that returns a Headline for each customer.
One Property, Shown Directly
{{ data_connection('DC_4ac341bd-1f2e-4c3d-9a8b-0c1d2e3f4a5b',customer.CustomerID,'Headline') | default: '' }}- If the customer has a row: the headline is shown.
- If there is no data: nothing is shown.
With Use default set to Your weekly offer, the end changes to | default: 'Your weekly offer' }}, and customers with no data see that text. With Drop customer, it changes to | drop_customer_if_null: 'no data for field Headline in dc 4ac341bd' }}, and customers with no data don't receive the message.
Several Properties in a Variable
When you select more than one property, the result is stored in a variable. You then show each property where you want it, with its own default.
{% assign loyalty_offers = data_connection('DC_4ac341bd-1f2e-4c3d-9a8b-0c1d2e3f4a5b',customer.CustomerID,'Headline,CTA') %}
{{ loyalty_offers.Headline | default: 'Your weekly offer' }}
{{ loyalty_offers.CTA | default: 'See offers' }}Result: the first line shows nothing; the next two show the customer's headline and button text, or the defaults when there is no data.
An API Connection with Parameters
API parameters sit between the lookup value and the property. Each one pairs a placeholder with the value you chose.
{{ data_connection('DC_9ce27b8c-2a3b-4c5d-8e9f-1a2b3c4d5e6f',customer.CustomerID,[['city','=',customer.City],['lang','=','en']],'current.temp_C') | default: '' }}Result: the API is called with the customer's city and en, and the temperature it returns is shown.
Use Case Examples
- Gaming: Upload a table of weekly VIP offers keyed by customer ID, then return its headline and button text in one lookup and show each in your email.
- Retail: Call your recommendations API with the customer's ID and preferred language, and show the first recommended product name.
- Travel: Call a weather API with the customer's home city and show today's temperature next to a destination offer.
FAQ
Why can't I find my data connection in the list?
The list shows your 100 most recently changed data connections, and search looks only within those. Deleted connections aren't listed. If you select an upload with no rows yet, the lookup tells you it has no rows.
Why is Use default greyed out?
You've selected more than one property, or a property that holds an object or a list, so the result goes into a variable. Add a default where you show each value instead, for example {{ loyalty_offers.Headline | default: 'Your weekly offer' }}.
Why did my settings disappear?
You chose a different data connection. Changing the connection clears the properties, lookup, parameters, fallback and output, because they belong to the connection you chose before.
Are test values written into my template?
No. Test values are used only when you click Fetch fields. At send time, each parameter uses the value you selected under Value.
What happens if my API returns an error at send time?
A "not found" answer counts as no data, so your fallback value applies. Any other error drops the customer from the send.
Can I edit the Liquid after I insert it?
Yes. The lookup inserts plain Liquid, so you can edit it in your template like any other code. Preview the template as a few customers afterwards to check the result.