Skip to main content
Contributor I
April 20, 2023
Solved

Campaign and Messages Endpoint

  • April 20, 2023
  • 3 replies
  • 242 views

I am migrating from v1-2 to v2023-02-22.

 

The email scheduler used to schedule emails using the “create_campaign” endpoint where options such as from_email, from_name, subject are set. But it seems that in v2023-02-22, the API has moved these options to the “Update Campaign Message” endpoint. However, during my testing, I am getting errors telling me to that the template cannot be changed directly, and asks me to use the assign campaign message template instead.

I am able to create a campaign and assign a template ID to it. But I am not able to change the fields such as “from_email”, from_name”, “subject_name”. Appreciate if someone can let me know what I am missing.

    This topic has been closed for replies.
    Best answer by Brian Turcotte

    Hi @douglaslo!

     

    I reproduced this with some internal engineers, and we found this method to accomplish your use case:

    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. In the response of the above call, you'll get the template ID and name
    4. Use that info to make a third API call to update the campaign message https://developers.klaviyo.com/en/reference/update_campaign_message
    5. If you get another error related to the template_name, you can just remove that attribute from the third API call

     

    I hope this helps!

     

    Best,

    Brian

     

     

    3 replies

    Brian Turcotte
    Klaviyo Alum
    April 21, 2023

    Hi @douglaslo!

     

    Would you be willing to post the exact error/screenshot (with all sensitive information redacted)? 

     

    This will help myself and other Community members understand the issue more clearly.

     

    Thanks,

    Brian

    douglasloAuthor
    Contributor I
    April 24, 2023

    Hi @douglaslo!

     

    Would you be willing to post the exact error/screenshot (with all sensitive information redacted)? 

     

    This will help myself and other Community members understand the issue more clearly.

     

    Thanks,

    Brian

    Hello @Brian Turcotte,

     

    Thank you very much for writing back. With the Python SDK, I am using the Campaigns.create_campaign() call to create a new campaign. This call is fine as I can see in the dashboard that I have successfully created a campaign.

     

    But after creating the campaign and getting the message I am getting a Bad Request Error.

     

    The call to update_campaign_message():

    klaviyo.Campaigns.update_campaign_message(message_id, {
    "data": {
    "type": "campaign-message",
    "id": message_id,
    "attributes": {
    "label": "",
    "content": {
    "subject": "My subject",
    "preview_text": "My preview text",
    "from_email": "hello@wateryeyes.hk",
    "from_label": "Wateryeyes",
    "template_id": KLAVIYO_TEMPLATE_ID,
    "template_name": "My tempalte"
    }
    }
    }
    })

    Error message as follows:

    HTTP response headers: HTTPHeaderDict({'Date': 'Mon, 24 Apr 2023 07:15:24 GMT', 'Content-Type': 'application/vnd.api+json', 'Content-Length': '241', 'Connection': 'keep-alive', 'CF-Ray': '7bcc8e0d2a4204d2-HKG', 'Allow': 'GET, PUT, PATCH, DELETE, HEAD, OPTIONS', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Vary': 'Cookie, Accept-Encoding', 'CF-Cache-Status': 'DYNAMIC', 'CID': 'YxvREs', 'Content-Security-Policy-Report-Only': "frame-ancestors 'self'; object-src 'none'; script-src 'strict-dynamic' 'unsafe-eval'; base-uri 'none'", 'RateLimit-Limit': '150, 10;w=1, 150;w=60', 'RateLimit-Remaining': '149', 'RateLimit-Reset': '27', 'X-Content-Type-Options': 'nosniff', 'X-Robots-Tag': 'noindex, nofollow', 'Server': 'cloudflare'})
    HTTP response body: {"errors":[{"id":"c5c90646-405c-4bf9-ba55-bcdd8c71b34a","status":400,"code":"error","title":"A server error occurred.","detail":"Template ID cannot be directly updated. Use the `assign-template` RPC instead.","source":{"pointer":"/data/"}}]}

    I am rather confused about the first parameter requesting for “message_id”, and the “message_id” within the “data” object. Not sure if they should be the same ID or not.

    Brian Turcotte
    Klaviyo Alum
    May 1, 2023

    Hi @douglaslo!

     

    I reproduced this with some internal engineers, and we found this method to accomplish your use case:

    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. In the response of the above call, you'll get the template ID and name
    4. Use that info to make a third API call to update the campaign message https://developers.klaviyo.com/en/reference/update_campaign_message
    5. If you get another error related to the template_name, you can just remove that attribute from the third API call

     

    I hope this helps!

     

    Best,

    Brian