尝试将新成员添加到 MailChimp 列表会导致错误 400(“此值不应为空”)

Posted

技术标签:

【中文标题】尝试将新成员添加到 MailChimp 列表会导致错误 400(“此值不应为空”)【英文标题】:Trying to add a new member to a MailChimp list results in error 400 ('This value should not be blank') 【发布时间】:2021-10-28 21:58:07 【问题描述】:

我正在尝试将新成员添加到 MailChimp 列表中,但我不断收到以下错误并且无法理解原因。


  type: 'https://mailchimp.com/developer/marketing/docs/errors/',
  title: 'Invalid Resource',
  status: 400,
  detail: "The resource submitted could not be validated. For field-specific details, see the 'errors' array.",
  instance: '/* secret */',
  errors: [
    
      field: 'email_address',
      message: 'This value should not be blank.'
    
  ]

代码如下:

const express = require("express");
const bodyParser = require("body-parser");
const request = require("request");
const https = require("https");

const app = express();

app.use(express.static("public"));

app.use(bodyParser.urlencoded(
  extended: true
));

app.get("/", function(req, res) 
  res.sendFile(__dirname + "/signup.html")
)

app.post("/", function(req, res) 
  const firstName = req.body.fname;
  const lastName = req.body.lname;
  const email = req.body.mail;
  console.log(firstName);
  console.log(lastName);
  console.log(email);

  const data = 
    members: [
      email_address: email,
      status: "Subscribed",
      merge_fields: 
        FNAME: firstName,
        LNAME: lastName
      
    ]
  ;
  const jsonData = JSON.stringify(data);
  const url = "https://us5.api.mailchimp.com/3.0/lists/4e5319cda3/members"
  const option = 
    method: "post",
    auth: "/* secret */"
  

  const request = https.request(url, option, function(response) 
    response.on(
      "data",
      function(data) 
        console.log(JSON.parse(data));
      )
  )

  request.write(jsonData);
  request.end();
);

app.listen(3000, function() 
  console.log("server is working in port 3000");
);

【问题讨论】:

你发送的是一个空白的email_address - 至少,这是错误告诉你的 - 也许你在你的javascript web-deployment mailchimp mailchimp-api-v3.0mailchimp-api-v3 请分享更多详细信息,例如涉及的代码以及您解决问题的尝试 app.post("/", function(req, res) const firstName = req.body.fname; const lastName = req.body.lname; const email = req.body.mail; console.log(firstName); console.log(lastName); console.log(email); const data = members: [ email_address: email, status: "Subscribed", merge_fields: FNAME: firstName, LNAME: lastName ] ; 请通过编辑添加所有说明到您的问题 【参考方案1】:

我认为 Mailchimp 的这个端点只接受一个元素而不是成员列表,尝试只发送一个成员

这是他们文档网站上的正文示例

"email_address":"","email_type":"","status":"subscribed","merge_fields":,"interests":,"language":"","vip":false,"location":"latitude":0,"longitude":0,"marketing_permissions":[],"ip_signup":"","timestamp_signup":"","ip_opt":"","timestamp_opt":"","tags":[]

在您的情况下,尝试将您的数据常量更改为:

  const data = 
  email_address: email,
  status: "Subscribed",
  merge_fields: 
    FNAME: firstName,
    LNAME: lastName
  
;

【讨论】:

以上是关于尝试将新成员添加到 MailChimp 列表会导致错误 400(“此值不应为空”)的主要内容,如果未能解决你的问题,请参考以下文章

MailChimp 重新订阅已删除的成员会导致 API 返回 400 错误请求

如何将标签添加到 Mailchimp 上的列表成员?

尝试在 mailchimp 中添加联系人时出现错误 400

Mailchimp 使用 php 和 drupal 8 将标签添加到列表中的现有成员

在列表 mailchimp api 中添加成员不起作用 [list memeber] cURL:提供的 API 密钥链接到不同的数据中心(状态:403)

将标签添加到 MailChimp 成员对象