Skip to main content
Question

How to Include Universal Content Blocks in Email Templates via API?


Forum|alt.badge.img+1

Hi everyone,

I'm trying to create an email template programmatically using the Klaviyo API (v2025-01-15) and want to include Universal Content Blocks in the template. Here’s what I’ve done so far:

  1. Fetched existing Universal Content Blocks using the /api/template-universal-content/ endpoint (https://developers.klaviyo.com/en/reference/get_all_universal_content) and found the ID of the block I want to include.
  2. Tried to create a new email template using /api/templates/, but I don’t see a documented way to reference Universal Content Blocks inside the template payload.

So a few questions:

  1. What would be the best way to allow for the creation of a new email template (or even just a wholesale new email campaign that is not a template) that includes existing universal content blocks?
  2. How can I fill in those blocks with variables (e.g for a product block, is there a way to specify which products it should fill in?)
Did this topic or the replies in the thread help you find an answer to your question?

5 replies

MANSIR2094
Problem Solver IV
Forum|alt.badge.img+15
  • Problem Solver IV
  • 231 replies
  • February 6, 2025

Hello ​@jason.brooks ,

Thank you for reaching out! You can include Universal Content Blocks in an email template via API by dynamically inserting the block’s ID into the html or mjml fields when creating the template. However, Klaviyo’s API doesn’t natively support referencing Universal Content Blocks directly in the payload. Instead, you need to fetch the block’s content, merge it into your template, and upload the final HTML.

 

For dynamic variables, you can use template tags ({{ variable_name }}) within the block content and pass data through campaign or flow parameters. If you need help implementing this efficiently, feel free to reach out.

 


Forum|alt.badge.img+1
  • Author
  • Contributor II
  • 3 replies
  • February 6, 2025

Hi ​@MANSIR2094 - thanks for the suggestion. Do you know how to fetch the block’s content? I attempted to use the API, but it’s not returning any content for the block, just metadata. For example:

 

curl --request GET \
  --url 'https://a.klaviyo.com/api/template-universal-content?=&page%5Bsize%5D=20' \
  --header 'Authorization: Klaviyo-API-Key pk_xxx' \
  --header 'Content-Type: application/json' \
  --header 'accept: application/json' \
  --header 'revision: 2024-10-15'

Response:

{
	"data": [
		{
			"type": "template-universal-content",
			"id": "xxx",
			"attributes": {
				"name": "Products",
				"definition": {
					"content_type": "block",
					"type": "product",
					"data": null
				},
				"created": "2025-02-06T12:52:13.422807+00:00",
				"updated": "2025-02-06T12:52:16.070859+00:00",
				"screenshot_status": "completed",
				"screenshot_url": "https://klaviyo-template-thumbnails.s3.amazonaws.com/saved_content/xxx"
			},
			"links": {
				"self": "https://a.klaviyo.com/api/template-universal-content/xxx/"
			}
		}
	],
	"links": {
		"self": "https://a.klaviyo.com/api/template-universal-content?page%5Bsize%5D=20",
		"next": null,
		"prev": null
	}
}

`data` appears to be null.


MANSIR2094
Problem Solver IV
Forum|alt.badge.img+15
  • Problem Solver IV
  • 231 replies
  • February 12, 2025

Hello ​@jason.brooks ,  sorry for late response …...
 

You're correct—the API currently returns only metadata and not the actual content of Universal Content Blocks. Unfortunately, Klaviyo’s API doesn’t provide a direct endpoint to fetch block content dynamically. The workaround is to manually extract the content from the Klaviyo editor and store it externally (e.g., in a database or CMS). Then, you can inject it into your template via API when needed.

For dynamic variables, you can use template tags ({{ variable_name }}) within the block content and pass data through campaign or flow parameters. Let me know if you need help setting this up efficiently!


Byrne C
Community Manager
Forum|alt.badge.img+12
  • Community Manager
  • 82 replies
  • February 14, 2025

Hi ​@jason.brooks,

I believe that you can retrieve the actual content of Universal Content blocks via the Get Universal Content call, but the reason you’re not seeing it in the response body you sent over is because you used the GET request on a product block. Right now, you can only get the actual content of text and HTML blocks. But in those cases, you should be able to get that content, and retrieve it. Let me know if this doesn’t work when attempting to do this for text/html blocks!

-Byrne


Adunni
Active Contributor II
Forum|alt.badge.img+1
  • Active Contributor II
  • 21 replies
  • February 16, 2025

Hi ​@jason.brooks ,

Great question! As of now, Klaviyo’s API does not provide a direct way to insert Universal Content Blocks into email templates via the /api/templates/ endpoint. However, here’s what you can do:

1. Workaround for Adding Universal Content Blocks

Since Universal Content Blocks are typically referenced in the Klaviyo template editor but not directly through the API, you might need to:
Manually add the Universal Content Block ID to your email template within Klaviyo’s editor after creating it via API.
Use Custom Properties or Variables in your template's HTML to replicate the functionality of Universal Content Blocks.

2. Filling Blocks with Variables (e.g., Product Data)

If you're working with dynamic product content, you can:
👉 Use Klaviyo’s event data (like {{ event.extra.Products }}) in your template.
👉 Pull product details from your Shopify integration and insert them dynamically in your API-generated template.
👉 Consider Custom Properties ($custom) for passing product-specific data into the email.

If you need a powerful solution to optimize this process, I can help you develop a structured approach for API-driven email templates in Klaviyo. Let’s make it work—reach out now!

Best,
Adunni