Skip to main content
Contributor II
December 12, 2023
Solved

Create a campaign with edited template via API

  • December 12, 2023
  • 10 replies
  • 407 views

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?

 

    This topic has been closed for replies.
    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.

    10 replies

    Brian Turcotte
    Klaviyo Alum
    December 13, 2023

    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

    JukkaAuthor
    Contributor II
    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
    Klaviyo Alum
    January 25, 2024

    Hi @Jukka!

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

    Best,

    Brian

    Contributor I
    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
    Klaviyo Alum
    February 6, 2024

    Hi @kalenjordan!

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

     

    Best,
    Brian

    Contributor I
    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.

    JukkaAuthor
    Contributor II
    March 20, 2024

    @Brian Turcotte do you know if this is fixed?

    Contributor I
    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.

    sparksAnswer
    Contributor I
    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
    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