-2

https://mailchimp.com/developer/marketing/api/lists/batch-subscribe-or-unsubscribe/ trying to implement this in express as practice for learning to work with API's but the server keeps returning code 400 and I can't figure out why when i'm just trying to add a email to my list on mailchimp using this.

const express = require("express");
const bodyParser = require("body-parser");
const request = require("request");
app=express();
app.use(bodyParser.urlencoded({ extended: true }));

var email;
var firstName;
var lastName;

app.use(express.static("public"));
app.listen(3000,() =>{
  console.log("Server is up and running on port 3000");
})

app.get("/signup", (req,res) =>{
res.sendFile(__dirname+"/signup.html");

});

app.post("/",(req,res) =>{
  firstName = req.body.firstName;
  lastName = req.body.lastName;
  email = req.body.userEmail;
  console.log(firstName,lastName,email);
});

var data = {
  members: [
    {
    email_address: email,
    status: "subscribed"
  }
]
};
var jsonData= JSON.stringify(data);

var options = {
  url: "https://us6.api.mailchimp.com/3.0/lists/e1c06c3202?skip_merge_validation=<false>&skip_duplicate_check=<true>",
  headers: {
    "Authorization" : "ItsCrux myapikey-us6"},
//I know, I have to use my actual key here that's not the problem
  body: jsonData,
  method: "POST"
};

request(options, (error, response, body) => {
if(error){
  console.log(error);
}
else{
  console.log(response.statusCode);
}
});

1 Answers1

-1

Try removing the < and > from the URL. Change ?skip_merge_validation=<false>&skip_duplicate_check=<true> to ?skip_merge_validation=false&skip_duplicate_check=true