Add a Custom Web Feed to a Campaign



In this article we walk through adding and using a custom web feed. The first step to adding external content to an email in Klaviyo is defining a web feed. A custom web feed is a URL you specify that contains the data for the content you want to add to your emails. Before sending an email, Klaviyo makes an HTTP request to the URL and fetches the data. The content of the web feed is then available for use in your email.

The power of web feeds is that they allow you to use a single template, but update the content used to render that template, so each email or campaign is different per send or even per recipient.

A common example of using a web feed is adding recent blog posts to your emails.


Please note that Klaviyo's custom web feed feature is only available for campaigns currently. It is not possible to use a custom feed in a flow email at this time.

Adding a Custom Web Feed

To add a web feed, navigate to the Data Feeds tab. If you haven't added a data feed before, you'll see a screen like this:

Click Add Web Feed.

You need to populate the following fields:

  • Feed Name: the identifier you use in your template to access the feed contents. Give your feed a short descriptive name. We recommend naming feeds either in camel case (e.g. "MyDataFeed") or all uppercase with spaces replaced by underscores (e.g. "MY_DATA_FEED").
  • Feed URL: the endpoint Klaviyo uses to fetch the feed contents. If your feed contains private information, we strongly recommend using an HTTPS URL and including a nonce query parameter to secure your feed.
  • Request Method: specifies the HTTP method that will be used to request your feed. We generally recommend GET, but you can also specify POST.
  • Content Type: specifies the format of the feed. The supported types are JSON and XML. We recommend using JSON if possible. For XML feeds, the feed will be converted to JSON.

Once you've filled out all the fields, click Add Data Feed.

Try it out

Want to try this out but don't have your own web feed URL? Use ours. Copy the following URL for the Klaviyo Help Center into the Feed URL box and try it out in your own Klaviyo account.

Klaviyo validates your feed and shows any potential errors. Once validated you see your feed in Klaviyo and it's ready to be used in emails.

Previewing your Web Feed

It's useful to preview a web feed before adding it to an email. To do this, click the Edit drop-down menu and select Preview.

On the next page, you'll see a preview of the content in your feed. If your feed is a JSON array, we'll automatically parse and show each row individually. If it's anything else, most likely a JSON dictionary, we'll show the entire dictionary.

If you are actively developing your feed, you can use the Refresh Feed button to pull the latest version of your feed. The preview page for a feed shows the entire feed. If your feed is large, it can take several seconds to display the contents.

Once you've added a web feed and previewed its contents, it's time to use it in a campaign.

Using a Web Feed in a Campaign

First, create a new email campaign. Once you've selected a template and are editing the email body, you can add one or more feeds to your campaign. In the footer of the email editor, click the Data Feeds link. Select the web feed you want to include in your campaign.


Remember, feeds are only available in campaign emails. If you created a template from a flow, or you are directly editing an email in our editor, you will not see the option to reference a data feed.

Klaviyo will fetch each feed once per campaign send, and store the returned content. Even if you're sending to thousands of recipients, Klaviyo won't make thousands of requests to your servers.

Populating Feed Content in your Template

The process for adding feed content to your emails varies if you're using a JSON Array or a JSON dictionary. We cover both methods in the sections below.

Using a JSON Array

In our example web feed, we have an array of locations where each entry includes a name, description and image. After a feed is added to a campaign, it's available through the feeds variable:

{{ feeds }}

For example, for the JSON feed above, we can now reference or output the contents of the tourists feed by including this syntax in our template:

{{ feeds.KlaviyoBlog }}

Let's run through an example where we iterate over all entries in the array, displaying certain variables. We'll use the KlaviyoBlog feed as an example here, and iterate over Images.

Step One: Insert a new text block

Step Two: Turn on the Repeat Block feature for.

To do this, click on the small hamburger menu in the upper right-hand corner of the text block.

For the Repeat For field, insert: feeds.YOUR FEED

For the Item Alias field, insert: item

In our example, because we are iterating over the "items" value as well, we will repeat for feeds.KlaviyoBlog.items 


If you only want this block to iterate over a certain number of entries, use the "slice" filter. To use this filter, adjust the Repeat For value by adding the filter to the end: 


In this example, the |slice:':3' will cause only the first three entries to display. 

Step Three: Insert Variables

Once you have configured the Repeat Block feature, you can insert whichever variables you'd like using the "item" alias, such as:

{{ }}
{{ item.images }}

Step Four: Preview

When you preview your template, you will notice that the Repeat Block feature will allow this simple text block to automatically iterate over all entries in your feed. Only the variables you specify in the text block will show for each entry.

If you are inserting an image, please note that you will need to edit the Source area of the text block and contain the image in an <img src> tag. 


Using a JSON Dictionary

Example: Iterate over all Blog Entries from a custom RSS feed

When you add a new RSS feed and click Preview, you will most likely see the following structure:

rss: { 
         channel: { 
                     item: { 

Step One: Create a Dynamic Table


You can alternatively use the Repeat Block feature outlined in Step Two above.

To create a Dynamic Table, drag over a regular Table Block and adjust to one column (removing the header text). Click over to Rows, and toggle the block from Static to Dynamic.

Step Two: Establish Data Source for Dynamic Table

Click on the Data Source tab after toggling your table to Dynamic. Insert the following as the source Row Collection field:

feeds.NAME OF

Insert the name of your feed where you see NAME OF FEED. Set the Row Alias to "item".

Step Three: Inserting Variables into Table

Next, you need to populate your table with the variables of your choice. You can find these variables when previewing your web feed.

Use of Django Filters

We support the use of all Django filters for the variables you insert.

Show only X number of recent posts

If you only want a dynamic table block to iterate over a certain number of entries, use the Slice Filter

To use this filter, adjust the Data Source value by adding the filter to the end. For example:

feeds.NAME OF|slice:':3'

In this example, the |slice:':3 will cause only the first three entries to display.

Limit post summary to X number of words

If you want to include a brief summary of each post under the post title (and your feed provides this summary text), you can use the Truncate Filter.


To limit the summary of an article to 250 characters, for example, you may do:

{{ item.summary|truncatechars: 250 }}

Was this article helpful?
16 out of 47 found this helpful