Setting Mailchimp campaign content html not working

梦想与她 提交于 2019-12-23 04:05:35

问题


I tried to update my campaign html content using mailchimp api:

/campaigns/{campaign_id}/content

You can find more information about this api here: https://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/content/#

Before sending a campaign, I tried to get campaign content html, modified it and then set campaign content html using above api. I just simply use BeautifulSoup to append a new tag to content body:

content.body.append(BeautifulSoup('<p>Mailchimp is freaking shittttt</p>'))

Then, some interesting things happen, the first campaign I created, it works fine, the tag added appears in my email. But, then the sub-sequence campaigns not working anymore, the tag added not appearing.

I observed something strange on my mailchimp campaign site, even though I set campaign html content, only Plain-Text Email gets changed (HTML Source still the old version) for both working and not working campaign.

Anyone got this issue before?


回答1:


I had a similar issue and I had to take a slightly different approach to solve it. According to this answer by Joel H., "MailChimp doesn't allow updating the campaign's HTML content because the campaign type is based on a template. In order to update the HTML content, the campaign has to be set to custom HTML instead of a template."

That solution didn't suit me but it led me to another solution: creating a template, creating editable content areas within that template, and then using the API to retrieve and edit the text in those content areas.

Here is an attempt at adapting my code to solve your problem. I'm using Python 3 and the mailchimp3 client.

default_footer_content = client.templates.default_content.all(template_id=TEMPLATE_ID)['sections']['SECTION_NAME']
new_footer_content = default_footer_content.replace(PLACEHOLDER, 'Mailchimp is freaking shittttt')
client.campaigns.content.update(campaign_id=CAMPAIGN_ID, data={'template': {'id': TEMPLATE_ID, 'sections': {'SECTION_NAME': new_footer_contennt}}})

Some pointers on the above code:

  1. You can find TEMPLATE_ID with the API or simply by copying the numbers at the end of the URL when editing the template in the web interface
  2. You define SECTION_NAME by placing 'mc:edit="SECTION NAME"' in the appropriate place in the template
  3. I've used .replace() rather than .append() so you will need to put PLACEHOLDER or similar at the appropriate place in the template

I hope that helps, happy to modify my answer if it needs more clarification. This is my first answer on Stack Overflow so constructive criticism appreciated :)



来源:https://stackoverflow.com/questions/47026542/setting-mailchimp-campaign-content-html-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!