Mailchimp API 未替换 mc:edit 内容部分(使用 ruby 库)
Mailchimp API not replacing mc:edit content sections (using ruby library)
我在用我提供的内容替换 Mailchimp 中的 mc:edit
内容区域时遇到问题。
电子邮件已发送给订阅者,但已将提供的 none 内容添加到电子邮件中。谁能看出我可能哪里出错了?
这是我正在使用的脚本:
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"])
这是电子邮件中我要修改的部分:
<div mc:edit="commit_stuff" class="mcnTextContent">Use your own custom HTML</div>
<div mc:edit="content"></div>
<div mc:edit="more-content"></div>
相关文档:
应该在 "content" 块内吗?在 API 示例中,我看到了这个:
},
"content": {
"html": "example html",
"sections": {
"...": "..."
},
"text": "example text",
"url": "example url",
"archive": "example archive",
"archive_type": "example archive_type"
},
我为此苦苦挣扎了几天,使用 MailChimp 中的模板管理器。我让它工作的唯一方法是导出我现有的模板,将 mc:edit 标记添加到代码中,然后将其作为自定义模板上传。
正在从 MailChimp 导出模板
- 转到'Templates'
- 单击要与 API
一起使用的模板旁边的 'Edit' 下拉箭头
- Select 'Export HTML'
正在将您的模板上传到 MailChimp
- 转到'Templates'
- 点击右上角的'Create Template '按钮
- 单击 'Code Your Own'
- 然后select'Import html'
我的模板代码示例:
<div mc:edit="eventmessage">
Custom Event Message (replaced by API Call)
<br></div>
作为检查,我现在能够看到使用 /templates/info API 调用时出现的部分
一旦我确认 Mailchimp 看到我使用 /campaigns/create 调用的模板部分,如上所述但跳过 html 定义。
已更新 campaign/create (content/sections):
},
"content": {
"sections": {
"eventmessage": "Event Message Content"
},
},
以下 PHP 代码对我有用
$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);
有一个端点可以设置内容以及可用的部分:
根据上面的@kateray 评论,经过一个小时的尝试,我设法通过其 API 3.0 从我的后端插入我的自定义 HTML 作为 MailChimp 活动内容。对于这样一个简单的用例,在他们的文档中没有现成的解决方案是相当烦人的。 MailChimp API 肯定缺少食谱。
所以从头开始:
a) 使用 API 或 MailChimp 网络界面创建邮件列表 - create list and b) add the recepients to it - add members.
通过 API create campaign 或他们的网站创建新的活动。 不要为其分配任何模板。
将邮件列表分配给活动 assign mailing list。
现在用 this API endpoint 设置活动内容。将以下值分配给您发送到端点的 请求的 JSON 正文:
{
"html": "<p>This is your custom HTML assigned to your campaign as content.</p>"
}
并发送请求。
在对此请求的响应中,您将获得您设置的 HTML 及其纯文本版本。
进入 MailChimp 网络界面并确保活动的所有复选标记都是绿色的。
发送 this API request 的活动。
注意:
- 仔细检查您是否为每个 API 请求使用了正确的 HTTP 动词:GET、PUT、PATCH、POST 如图所示 in the API reference
- 别忘了authenticate your API calls, here is the quick intro with clean examples made in Postman
- 仔细检查您在 API 请求中传递了正确的列表 ID、活动 ID。
我在用我提供的内容替换 Mailchimp 中的 mc:edit
内容区域时遇到问题。
电子邮件已发送给订阅者,但已将提供的 none 内容添加到电子邮件中。谁能看出我可能哪里出错了?
这是我正在使用的脚本:
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"])
这是电子邮件中我要修改的部分:
<div mc:edit="commit_stuff" class="mcnTextContent">Use your own custom HTML</div>
<div mc:edit="content"></div>
<div mc:edit="more-content"></div>
相关文档:
应该在 "content" 块内吗?在 API 示例中,我看到了这个:
},
"content": {
"html": "example html",
"sections": {
"...": "..."
},
"text": "example text",
"url": "example url",
"archive": "example archive",
"archive_type": "example archive_type"
},
我为此苦苦挣扎了几天,使用 MailChimp 中的模板管理器。我让它工作的唯一方法是导出我现有的模板,将 mc:edit 标记添加到代码中,然后将其作为自定义模板上传。
正在从 MailChimp 导出模板
- 转到'Templates'
- 单击要与 API 一起使用的模板旁边的 'Edit' 下拉箭头
- Select 'Export HTML'
正在将您的模板上传到 MailChimp
- 转到'Templates'
- 点击右上角的'Create Template '按钮
- 单击 'Code Your Own'
- 然后select'Import html'
我的模板代码示例:
<div mc:edit="eventmessage">
Custom Event Message (replaced by API Call)
<br></div>
作为检查,我现在能够看到使用 /templates/info API 调用时出现的部分
一旦我确认 Mailchimp 看到我使用 /campaigns/create 调用的模板部分,如上所述但跳过 html 定义。
已更新 campaign/create (content/sections):
},
"content": {
"sections": {
"eventmessage": "Event Message Content"
},
},
以下 PHP 代码对我有用
$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);
有一个端点可以设置内容以及可用的部分:
根据上面的@kateray 评论,经过一个小时的尝试,我设法通过其 API 3.0 从我的后端插入我的自定义 HTML 作为 MailChimp 活动内容。对于这样一个简单的用例,在他们的文档中没有现成的解决方案是相当烦人的。 MailChimp API 肯定缺少食谱。
所以从头开始:
a) 使用 API 或 MailChimp 网络界面创建邮件列表 - create list and b) add the recepients to it - add members.
通过 API create campaign 或他们的网站创建新的活动。 不要为其分配任何模板。
将邮件列表分配给活动 assign mailing list。
现在用 this API endpoint 设置活动内容。将以下值分配给您发送到端点的 请求的 JSON 正文:
{
"html": "<p>This is your custom HTML assigned to your campaign as content.</p>"
}
并发送请求。
在对此请求的响应中,您将获得您设置的 HTML 及其纯文本版本。
进入 MailChimp 网络界面并确保活动的所有复选标记都是绿色的。
发送 this API request 的活动。
注意:
- 仔细检查您是否为每个 API 请求使用了正确的 HTTP 动词:GET、PUT、PATCH、POST 如图所示 in the API reference
- 别忘了authenticate your API calls, here is the quick intro with clean examples made in Postman
- 仔细检查您在 API 请求中传递了正确的列表 ID、活动 ID。