[英]I can't figure out why I am getting the following error "Error: Element type is invalid:"
[英]Can't figure out why I am getting this error in my terminal while creating a webpage with the help of API
这是我的 javascript 代码。 当我使用 nodemon 运行它时,我的终端出现错误。 错误在代码底部提到
const express=require("express");
const bodypraser=require("body-parser");
const request =require("request");
const https=require("https");
const app=express();
app.use(express.static("public"));
app.use(bodypraser.urlencoded({extended:true}))
从路线发帖
app.post("/",function(req,res)
{
const firstname=req.body.fname;
const lastname=req.body.lname;
const email=req.body.email;
const data={
members:[
{
email_address:email,
status:"suscribed",
merge_fields:{
FNAME:firstname,
LNAME:lastname
}
}
]};
const jsondata=JSON.stringify(data);
const url= "https://us1.api.mailchimp.com/3.0/lists/a6b99f4c3c";
创建选项 object
const options={
method:"POST",
auth:"deco:d6550609e1d79db44b409d81841d74bf-us1"
}
const request=https.request(url,options,function(response){
response.on("data",function(data){
console.log(JSON.parse(data));
})
})
request.write(jsondata);
request.end();
});
app.get("/" ,function(req ,res){
res.sendFile(__dirname+"/signup.html");
});
app.listen(3000,function(req,res){
console.log("ok ");
});
代码结束
{
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: '26cacd7a-d1b6-4195-9407-9eb39a9ec224',
errors: [
{
field: 'members.item:0.status',
message: 'Data presented is not one of the accepted values: subscribed,
unsubscribed, cleaned, pending.'
}
]
}
阅读错误信息。 Mailchimp 要求status
是错误中提到的四个值之一。 您的状态有两个拼写错误(状态:“已订阅”)而不是已订阅(注意区分大小写)。
下次您发布问题时,请使用正确的代码缩进。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.