Skip to main content
Solved

Create a campaign with edited template via API


Forum|alt.badge.img+1
  • Contributor II
  • 4 replies

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?

 

Best answer by sparks

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.

View original
Did this topic or the replies in the thread help you find an answer to your question?

10 replies

Brian Turcotte
Forum|alt.badge.img+37

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


Forum|alt.badge.img+1
  • Author
  • Contributor II
  • 4 replies
  • December 14, 2023

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:

 


Brian Turcotte
Forum|alt.badge.img+37

Hi @Jukka!

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

Best,

Brian


Forum|alt.badge.img
  • Contributor I
  • 2 replies
  • January 29, 2024

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.

 

 


Brian Turcotte
Forum|alt.badge.img+37

Hi @kalenjordan!

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

 

Best,
Brian


Forum|alt.badge.img
  • Contributor I
  • 2 replies
  • February 7, 2024

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.


Forum|alt.badge.img+1
  • Author
  • Contributor II
  • 4 replies
  • March 20, 2024

@Brian Turcotte do you know if this is fixed?


  • Contributor I
  • 2 replies
  • April 7, 2024

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.


  • Contributor I
  • 2 replies
  • Answer
  • April 8, 2024

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.


  • Contributor I
  • 1 reply
  • September 13, 2024

@Brian Turcotte 

This appears to still be a reproducable error.

Just today I can create a campaign via the API, assign a template to the new campaign’s Campaign Message, and receive a (cloned) template ID back.

The API shows the cloned template in the response for Getting all Templates

The API shows the cloned template in the response to Get that one, cloned Template by ID

When attempting the PATCH to update this cloned template by ID, the response is a 404 error that the template “does not exist”. (It very much does, though)

 

Here’s a Call ID for a valid GET request for this template: 

97118f00-fbc7-48cf-a808-2ab1d0314623

 

Here’s a call ID for a failed PATH request for the same template: 

4bfdf297-8473-4bc4-adce-5dd2be8dbd6d

 

Can this please be remediated?

 

GET success response

PATCH error response