The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

400 Status Code — Bad Request

Occasional Organizer

400 Status Code — Bad Request

Hello

I am new to setting up email API. I am struggling to make this work with Constant Contact.

I am using node.js with Express, and using Request as my HTTP client. Something is not configured correctly in my options or the data I am using to make the post request. My form has three inputs: First Name, Last Name and Email. Can someone with knowledge of this approach help me out?
Thank you

 

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

const app = express();

app.use(express.static("public"));
app.use(
  bodyParser.urlencoded({
    extended: true
  })
);

app.get("/"function(reqres) {
  res.sendFile(__dirname + "/signup.html");
});

app.post("/"function(reqres) {
  let firstName = req.body.fName;
  let lastName = req.body.lName;
  let email = req.body.email;

  let data = {
    first_name: firstName,
    last_name: lastName,
    email_address: email
  };

  let jsonData = JSON.stringify(data);

  let options = {
    url:
    method: "POST",
    headers: {
      Authorization: "Bearer xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    },
    body: jsonData
  };

  request(optionsfunction(errorresponsebody) {
    console.log(response.statusCode);
  });
});

app.listen(3000function() {
  console.log("server has started on port 3000");
});
 
*moderator note: edited content for privacy
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured