Solved

Create a campaign with edited template via API

  • 12 December 2023
  • 9 replies
  • 128 views

Badge

Hello,

I am trying to create a campaign via the API but I don’t see how to update the template after it’s being assigned to the campaign.

This is what I am doing:

  1. Create a campaign using https://developers.klaviyo.com/en/reference/create_campaign
  2. Assign a message template to the campaign using https://developers.klaviyo.com/en/reference/create_campaign_message_assign_template
  3. Here I get a new template ID and a campaign ID

 

Now how can I modify the template assigned to this campaign without modifying the original template?

 

icon

Best answer by sparks 8 April 2024, 16:46

View original

9 replies

Userlevel 7
Badge +36

Hi @Jukka!

 

It is possible to edit HTML templates via API, but it depends on exactly what you’re trying to do. If you modify the template with template ID referenced by the campaign message, that would modify the campaign template only, and not the original template.

 

Best,

Brian

Badge

Hi @Brian Turcotte that’s exactly what I am trying to do but the API return 404 Not found with this template ID.

 

If I try to modify the original template_id it works but if I try to modify the template_id I receive during the creating of campaign message (still via the API) it just give me a 404 not found.

 

This is the Template: (Created during assignation)

 

This is when I try to update it:

 

Userlevel 7
Badge +36

Hi @Jukka!

I’ve been informed that this should have been fixed - are you still experiencing this issue?

Best,

Brian

I just ran into this same exact issue today as well. Getting a 404 when I PATCH the template - GET for the same template ID works just fine.

 

 

Userlevel 7
Badge +36

Hi @kalenjordan!

I’ll check on this with our API team to see if this happening to others.

 

Best,
Brian

This is definitely still happening. I just created a campaign and assigned an existing template to it. It then returned with a new template id (for the cloned template assigned to the campaign message).

When I make a GET request to get this new template data, everything is ok.

However, if I try to update the template html for example, it returns a 404. Its possible you guys fixed that one endpoint but forgot the other.

Badge

@Brian Turcotte do you know if this is fixed?

Any update on this? I am having the same problem as @aguerrero. The GET request returns the template data, but PATCH returns with:

Template with id 'QUrd7f' does not exist

 

If there are no immediate plans to fix this, is there a different way to achieve the same result? I basically have a template with custom variables that I am updating on a per campaign basis. It’s a “question of the day” email so each day’s campaign has a different question in it.

In case anyone else is dealing with this same thing, here’s a workaround that worked for me:

I created a web feed (https://help.klaviyo.com/hc/en-us/articles/115005258768), then used custom variables in the template (like {{ feeds.MyFeedName.fieldName }} ).

Then I created a function on my site that runs once a day that does the following:

  1. Creates a campaign (https://developers.klaviyo.com/en/reference/create_campaign)
  2. Assigns the template to the campaign (https://developers.klaviyo.com/en/reference/create_campaign_message_assign_template)
  3. Sends the campaign (https://developers.klaviyo.com/en/reference/create_campaign_send_job)

This causes the system to use the web feed to populate the variables and properly sends the finalized email campaign.

Reply