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?

2 replies

MANSIR2094
Problem Solver IV
Forum|alt.badge.img+13
  • Problem Solver IV
  • 174 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.