Search code examples
javascriptnode.jsexpressterminalmailchimp-api-v3.0

Resource submitted could not be validated: Mailchimp


as this is my first question on StackOverflow, I do hope I provide you with enough details to the problem in order to fix it. If you need any further info, don't hesitate to ask.

In short, I'm trying to create a simple signup page for a newsletter that adds subscribers to Mailchimp.

In the terminal/command-line I get this message:

{ 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: '4d92a5b7-20fb-4f1c-be19-fbcd6548e745', errors: [ { field: '', message: 'Required fields were not provided: email_address' } ] }

My HTML-body looks like this:

`

<img class="mb-4" src="images/logo.png" alt="" width="172" height="172">
<h1 class="h3 mb-3 font-weight-normal">Signup to our Newsletter</h1>

<input type="text" name="fName" class="form-control top" placeholder="First Name"  required autofocus>
<input type="text" name="lName" class="form-control middle" placeholder="Last Name"  required>
<input type="email" name="email" class="form-control bottom" placeholder="Email" required>



<button class="btn btn-lg btn-primary btn-block btn-sign-up" type="submit">Sign me up!</button>

<p class="mt-5 mb-3 text-muted">&copy; PB Plus 2017-2020</p>

`

This is the 'POST' part of my Javascript:

app.post("/", function(req, res) {

  const firstName = req.body.fName;
  const lastName = req.body.lName;
  const mail = req.body.email;

  const data = {
    members: [{
      email_adress: mail,
      status: "subscribed",
      merge_fields: {
        FNAME: firstName,
        LNAME: lastName
      }
    }]
  };

  var jsonData = JSON.stringify(data);

  const url = "https://us4.api.mailchimp.com/3.0/lists/fae76eccaf";
  const options = {
    method: "POST",
    auth: "xavier1:6cbb8e0a03109b3b2ef74adc0127f986-us4"
  }

  const request = https.request(url, options, function(response) {

    if (response.statusCode === 200) {
      res.sendFile(__dirname + "/succes.html");
    } else {
      res.sendFile(__dirname + "/failure.html");
    }

    response.on("data", function(data) {
      console.log(JSON.parse(data));
    })
  })

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

})

If anyone knows what I did wrong, please let me know! Thanks in advance.


Solution

  • Well, After spending many hours figuring out what's wrong, I typed email_adress instead of email_address. Problem solved.