我正在尝试使用 node.js 的 mailchimp-api 将用户 emailId 添加到邮件列表。我编写了以下函数。
subscribeEmail: function(listId, emailId) {
var mcapi = require("mailchimp-api");
mc = new mcapi.Mailchimp('api-key');
console.log(emailId);
mc.lists.subscribe({id: listId, email: [ {'email': emailId } ]}, function(data) {
console.log("Successfully Subscribed");
},
function(error) {
if (error.error) {
console.log(error.code + ": " + error.error);
} else {
console.log('There was an error subscribing that user');
}
});
}
我最终收到以下错误,
-100: The email parameter should include an email, euid, or leid key
有没有人对原因有任何建议。任何帮助将不胜感激。干杯!
最佳答案
你犯了一个简单的错误。
这一行:
mc.lists.subscribe({id: listId, email: [ {'email': emailId } ]}, function(data) {
应该看起来像这样:
mc.lists.subscribe({id: listId, email: {'email': emailId }}, function(data) {
说明:
您正在将对象 [ {'email': emailId } ]
传递给函数,但它需要一个值:{'email': emailId }
来自 github Express 的示例代码 example app :
mc.lists.subscribe({
id: req.params.id,
email: {
email: req.body.email
}
}, function(data) {
req.session.success_flash = 'User subscribed successfully! Look for the confirmation email.';
res.redirect('/lists/' + req.params.id);
}
关于javascript - 使用 node.js 的 mailchimp-api 插件将用户添加到 mailchimp 邮件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32722686/