sdkdeepa/Udemy-web-bootcamp

Issue with Post method in Newsletter App

moktan456 opened this issue · 1 comments

I tried exactly the same code but it is not working. But when I try to use the new version from Mailchimp it works but when i try to access response.statusCode, it say undefined. Could you kindly check one.
Here is the snippet of my code.

app.post("/",(req,res)=>{
const fName = req.body.fName;
const lName = req.body.lName;
const email = req.body.email;
client.setConfig({
apiKey: "f45c07cf2dd7d45af20f0b083aba6261-us14",
server: "us14",
});
const run = async () => {
const response = await client.lists.addListMember("8041b6b1ac",
{
email_address: email,
status: "subscribed",
merge_fields: {
FNAME: fName,
LNAME: lName,
},
},

        {
            skipMergeValidation: false
        }
    );
    console.log(`This user's subscription status is ${response.status}.`);
};

run();

});

Thanks for the update! This was an yr and half ago. Will check and add changes. Please do not expose the api key in your code. Have it in an environmental variables file and add it to git ignore.