12

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:

Eleanor Zimmermann
  • 414
  • 1
  • 8
  • 26
Edd Slipszenko
  • 396
  • 3
  • 17
  • 1
    Nothing obvious is jumping out to me as being wrong with this. My first debugging trick would be to see what actual JSON the library is creating and compare that to the actual API docs. Another might be to create the campaign without the content and then add the content in another step. Still, this sounds like something MailChimp's API support team would be able to sort out really quickly. apihelp [at] mailchimp to get in touch with them. – TooMuchPete Apr 12 '15 at 19:03
  • 1
    Couldn't find anything wrong either. One thing I did read in the docs is that the mc:edit's cannot be nested in your HTML template, so that might be something to check for. Another idea for debugging this: I would also try boiling this down to the simplest possible template, with just once mc:edit tag, and seeing if that at least works. That way you'll get an idea if it might be something in the way your template is set up. – Oliver Nicolaas Ponder Apr 13 '15 at 20:41
  • I am having exactly the same issue, although using php library. In the end, did you succeed to make it work? – PIIANTOM Jul 01 '15 at 00:39
  • No, unfortunately I've still had no luck. Please let me know if you do. – Edd Slipszenko Jul 01 '15 at 09:14
  • Any updates on this question at this point? I'm looking to do something similar within my content management system and wondering if this is even possible. – Kory Sharp Aug 28 '15 at 22:30
  • I've still not had any luck. For the moment we've abandoned the task – Edd Slipszenko Aug 31 '15 at 08:07
  • @KorySharp, I made a [detailed explanation here](https://thedebuggers.com/send-mailchimp-newsletter-via-php/) – Valentine Shi Nov 01 '18 at 07:56

5 Answers5

16

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"
    },

},
greggturnbull
  • 176
  • 1
  • 3
  • 9
    I spoke to support and can confirm that the ONLY way to use their template language is in a custom-coded template: "So, I can see that that template is Drag and Drop, and it's not possible to use that template language in those. Because we've already pre-specified the editable sections there, trying to add that in can cause issues. Instead, you would need to use a completely custom coded template." – kateray Oct 30 '15 at 19:52
  • I've run into the same problem w/v3.0 of their API. Even though I went through the process above, otherwise successful calls to their campaign/{id}/content endpoint do NOT successfully update the editable sections of a campaign's template.The only option I can think of at this point is to build the HTML on our end and simply set the campaign's HTML content and skip using a template. Or use v2.0 like this answer is. – jewel Jan 22 '16 at 22:41
  • butt-average imho. surely their API docs could disclose the info you discovered by *phoning* them (or they could just fix their API) – wal Feb 13 '17 at 15:36
  • @greggturnbull you've saved my head from blowing up! Also spent a day figuring this one out! What a hidden gem! – timonweb Oct 26 '18 at 14:27
5

As per @kateray comment above, after an hour of tries I managed to insert my custom HTML from my back-end as the MailChimp campaign content via its API 3.0. For such a simple use case it is rather annoying not to have a ready-made solution on their docs. Surely MailChimp API lacks a cookbook.

So from the beginning:

  1. a) Create the mailing list with API or with MailChimp web interface - create list and b) add the recepients to it - add members.

  2. Create the new campaign via API create campaign or their website. Do not assign any template to it.

  3. Assign the mailing list to the camplaign assign mailing list.

  4. Now set the campaign content with this API endpoint. Assign the following value to the JSON body of the request you send to the endpoint:

{
    "html": "<p>This is your custom HTML assigned to your campaign as content.</p>"
}

and send the request.

  1. In the response to this request you get the HTML you set and its plain text version.

  2. Go in the MailChimp web interface and ensure the campaign has all the check marks green.

  3. Send out the campaign with this API request.

NB:

Valentine Shi
  • 6,604
  • 4
  • 46
  • 46
2

There's an endpoint to set the content along with the sections available at:

https://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/content/#edit-put_campaigns_campaign_id_content

Mike Doe
  • 16,349
  • 11
  • 65
  • 88
0

Should that be inside a "content" block? In the API example I see this:

    },
    "content": {
        "html": "example html",
        "sections": {
            "...": "..."
        },
        "text": "example text",
        "url": "example url",
        "archive": "example archive",
        "archive_type": "example archive_type"
    },
Ralpharama
  • 441
  • 4
  • 20
-6

Following PHP code worked for me

$api = new MCAPI($apikey);

$type = 'regular';

$opts['list_id'] = 'id';
$opts['subject'] = 'The subject';
/*<div mc:edit="std_content00">*/
$content = array('html_std_content00'=> $template);

$retval = $api->campaignCreate($type, $opts, $content);
Clintu
  • 25
  • 4