Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require("express");
- const app = express();
- const bodyParser = require("body-parser");
- const https = require("https");
- const mailchimp = require("@mailchimp/mailchimp_marketing");
- app.use(bodyParser.urlencoded({ encoded: true }));
- app.use(express.static(__dirname));
- mailchimp.setConfig({
- apiKey: "d2ab303c1691857e14371bfb792d3730-us5",
- server: "us5",
- });
- app.get("/", function (req, res) {
- res.sendFile(__dirname + "/signup.html");
- });
- app.post("/", function (req, res) {
- const listId = "81f92b5588";
- const subscribingUser = {
- firstName: req.body.firstName,
- lastName: req.body.lastName,
- email: req.body.email,
- };
- async function run() {
- const response = await mailchimp.lists.addListMember(listId, {
- email_address: subscribingUser.email,
- status: "subscribed",
- merge_fields: {
- FNAME: subscribingUser.firstName,
- LNAME: subscribingUser.lastName,
- },
- });
- console.log(
- `Successfully added contact as an audience member. The contact's id is ${response.id}.`
- );
- }
- run();
- });
- app.listen(3000, function () {
- console.log("Server started at http://localhost:3000/");
- });
- //API Key
- //d2ab303c1691857e14371bfb792d3730-us5
- //List ID
- //81f92b5588
Advertisement
Add Comment
Please, Sign In to add comment