Edd Slipszenko Edd Slipszenko - 5 months ago 94
Ruby Question

Mailchimp API not replacing mc:edit content sections (using ruby library)

I'm having a problem replacing

mc:edit
content areas in Mailchimp with the content that I provide.

The email is sent out to the subscribers, but none of the content provided is added to the email. Can anyone see where I might be going wrong?

This is the script that I am using:

campaign = mailchimp.campaigns.create(
"regular",
{
"list_id" => list_id,
"subject" => "Email Test",
"from_email" => "edward@somewhere.com",
"from_name" => "Edward",
"to_name" => "The to name",
"template_id" => 35089
},
{
"sections" =>
{
"commit_stuff" => "Modified project to use XYZ ruby gem. #ABC-123",
"content" => "This is the content",
"more-content" => "This is more content"
}
}
)
result = mailchimp.campaigns.send(campaign["id"])


And this is the section inside the email that I am trying to modify:

<div mc:edit="commit_stuff" class="mcnTextContent">Use your own custom HTML</div>

<div mc:edit="content"></div>

<div mc:edit="more-content"></div>


Relevant docs:


Answer

I struggled with this for a few days, using the template manager in MailChimp. The only way I got it to work was exporting my existing template, adding the mc:edit tag to the code and then uploading it as a custom template.

Exporting template from MailChimp

  • Go to 'Templates'
  • Click on the 'Edit' drop down arrow, next to the template you want to use with the API
  • Select 'Export HTML'

Uploading your template to MailChimp

  • Go to 'Templates'
  • Click the 'Create Template ' button in the top right
  • Click the 'Code Your Own'
  • Then select 'Import html'

Example of my template code:

<div mc:edit="eventmessage">
Custom Event Message (replaced by API Call)
<br></div>

As a check, I was now able to see the section now appear when using /templates/info API call

Once I confirmed that Mailchimp saw the template section I used /campaigns/create call, as mentioned above but skipping over the html definition.

Updated campaign/create (content/sections):

    },
"content": {
    "sections": {
        "eventmessage": "Event Message Content"
    },

},