Mailchimp API不替换mc:编辑内容部分(使用ruby库)

我在替换mc:edit遇到问题mc:edit使用我提供的内容mc:edit Mailchimp中的内容区域。

电子邮件将发送给订阅者,但所提供的内容都不会添加到电子邮件中。 谁能看到我可能会出错的地方?

这是我正在使用的脚本:

 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"]) 

这是我试图修改的电子邮件中的部分:

 
Use your own custom HTML

相关文档:

  • API https://apidocs.mailchimp.com/api/2.0/campaigns/create.php
  • 图书馆http://www.rubydoc.info/gems/mailchimp-api/2.0.4/Mailchimp/Campaigns#create-instance_method

使用MailChimp中的模板管理器,我在这里挣扎了几天。 我让它工作的唯一方法是导出我现有的模板,将mc:edit标签添加到代码中,然后将其作为自定义模板上传。

从MailChimp导出模板

  • 转到“模板”
  • 单击要与API一起使用的模板旁边的“编辑”下拉箭头
  • 选择“导出HTML”

将模板上传到MailChimp

  • 转到“模板”
  • 单击右上角的“创建模板”按钮
  • 点击“自己编码”
  • 然后选择’导入html’

我的模板代码示例:

 
Custom Event Message (replaced by API Call)

作为检查,我现在能够看到使用/ templates / info API调用时现在出现的部分

一旦我确认Mailchimp看到模板部分我使用/ campaigns / create call,如上所述但跳过html定义。

更新了广告系列/创建(内容/部分):

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

它应该在“内容”区块内吗? 在API示例中,我看到:

  }, "content": { "html": "example html", "sections": { "...": "..." }, "text": "example text", "url": "example url", "archive": "example archive", "archive_type": "example archive_type" }, 

根据上面的@kateray评论,经过一个小时的尝试后,我设法通过其API 3.0从我的后端插入我的自定义HTML作为MailChimp campain内容。 对于这样一个简单的用例,在他们的文档上没有现成的解决方案是相当烦人的。 当然,MailChimp API缺少一本食谱。

所以从开始:

  1. a)使用API​​或MailChimp Web界面创建邮件列表 – 创建列表和b)向其添加接收者 – 添加成员 。

  2. 通过API 创建广告系列或其网站制作新广告系列 。 不要为其分配任何模板

  3. 将邮件列表分配给 camplaign 分配邮件列表 。

  4. 现在使用此API端点设置广告系列内容。 将发送到端点的请求的JSON主体设置为:

{ "html": "

This is your custom HTML assigned to your campaign as content.

" }并发送请求。

  1. 在对此请求的响应中,您将获得您设置的HTML及其纯文本版本。

  2. 进入MailChimp网络界面,确保广告系列的所有复选标记均为绿色。

  3. 使用此API请求发送广告系列。

注意:

  • doublecheck为每个API请求使用正确的HTTP谓词:GET,PUT,PATCH,POST,如API参考中所示
  • 不要忘记validation您的API调用 ,这里是Postman中提供的简洁示例的快速介绍
  • 请仔细检查您是否在API请求中传递了正确的列表ID,广告系列ID。

以下PHP代码为我工作

 $api = new MCAPI($apikey); $type = 'regular'; $opts['list_id'] = 'id'; $opts['subject'] = 'The subject'; /*
*/ $content = array('html_std_content00'=> $template); $retval = $api->campaignCreate($type, $opts, $content);