Mailchimp Api 无法获取我发送的 email_address 字段
Mailchimp Api is unable to get the email_address field I send
我正在尝试使用 mailchimp API 以便为用户订阅现有列表。
使用节点 https 请求,我向 mailchimp 服务器发送以下请求:
const url = `https://us7.api.mailchimp.com/3.0/lists/<list_id>/members?skip_merge_validation=true'`;
const options = {
method: "POST",
auth: "<name>:<API Key>",
};
const request = https.request(url, options, (response) => {
response.on("data", (data) => {
console.log(JSON.parse(data));
if (data.status === 200) {
res.redirect("/sucess");
} else {
res.redirect("/failure");
}
});
});
request.write(JSON.stringify(user_data));
request.end();
});
在发出请求之前,我console.log从前端收集的用户数据。
console.log("USER DATA : " + JSON.stringify(user_data));
这是我从 API 服务器得到的答案:
USER DATA : {"members":[{"email_address":"a.b@email.com","status":"subscribed","merge_fields":{"FNAME":"A","LNAME":"B"}}]}
{
type: 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/',
title: 'Invalid Resource',
status: 400,
detail: "The resource submitted could not be validated. For field-specific details, see the 'errors' array.",
instance: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
errors: [
{
field: 'email_address',
message: 'This value should not be blank.'
}
]
}
如您在日志中所见,email_address 字段不是空白。
有没有人遇到过这个问题?有任何想法吗 ?
提前致谢
我找到了问题,它与我的用户数据结构有关。它现在正在使用以下代码
const user_data = {
email_address: req.body.email,
status: "subscribed",
merge_fields: {
FNAME: req.body.fName,
LNAME: req.body.lName,
}
}
我正在尝试使用 mailchimp API 以便为用户订阅现有列表。
使用节点 https 请求,我向 mailchimp 服务器发送以下请求:
const url = `https://us7.api.mailchimp.com/3.0/lists/<list_id>/members?skip_merge_validation=true'`;
const options = {
method: "POST",
auth: "<name>:<API Key>",
};
const request = https.request(url, options, (response) => {
response.on("data", (data) => {
console.log(JSON.parse(data));
if (data.status === 200) {
res.redirect("/sucess");
} else {
res.redirect("/failure");
}
});
});
request.write(JSON.stringify(user_data));
request.end();
});
在发出请求之前,我console.log从前端收集的用户数据。
console.log("USER DATA : " + JSON.stringify(user_data));
这是我从 API 服务器得到的答案:
USER DATA : {"members":[{"email_address":"a.b@email.com","status":"subscribed","merge_fields":{"FNAME":"A","LNAME":"B"}}]}
{
type: 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/',
title: 'Invalid Resource',
status: 400,
detail: "The resource submitted could not be validated. For field-specific details, see the 'errors' array.",
instance: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
errors: [
{
field: 'email_address',
message: 'This value should not be blank.'
}
]
}
如您在日志中所见,email_address 字段不是空白。
有没有人遇到过这个问题?有任何想法吗 ?
提前致谢
我找到了问题,它与我的用户数据结构有关。它现在正在使用以下代码
const user_data = {
email_address: req.body.email,
status: "subscribed",
merge_fields: {
FNAME: req.body.fName,
LNAME: req.body.lName,
}
}