BetinaUKTC

MailChimp add

Sep 11th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. const express = require("express");
  2. const app = express();
  3. const bodyParser = require("body-parser");
  4. const https = require("https");
  5. const mailchimp = require("@mailchimp/mailchimp_marketing");
  6.  
  7. app.use(bodyParser.urlencoded({ encoded: true }));
  8. app.use(express.static(__dirname));
  9.  
  10. mailchimp.setConfig({
  11. apiKey: "d2ab303c1691857e14371bfb792d3730-us5",
  12. server: "us5",
  13. });
  14.  
  15. app.get("/", function (req, res) {
  16. res.sendFile(__dirname + "/signup.html");
  17. });
  18.  
  19. app.post("/", function (req, res) {
  20. const listId = "81f92b5588";
  21. const subscribingUser = {
  22. firstName: req.body.firstName,
  23. lastName: req.body.lastName,
  24. email: req.body.email,
  25. };
  26.  
  27. async function run() {
  28. const response = await mailchimp.lists.addListMember(listId, {
  29. email_address: subscribingUser.email,
  30. status: "subscribed",
  31. merge_fields: {
  32. FNAME: subscribingUser.firstName,
  33. LNAME: subscribingUser.lastName,
  34. },
  35. });
  36.  
  37. console.log(
  38. `Successfully added contact as an audience member. The contact's id is ${response.id}.`
  39. );
  40. }
  41.  
  42. run();
  43. });
  44.  
  45. app.listen(3000, function () {
  46. console.log("Server started at http://localhost:3000/");
  47. });
  48.  
  49. //API Key
  50. //d2ab303c1691857e14371bfb792d3730-us5
  51.  
  52. //List ID
  53. //81f92b5588
  54.  
Advertisement
Add Comment
Please, Sign In to add comment