total amateur here with the following code:
app.post("/", (req, res) => {
const firstName = req.body.fname;
const lastName = req.body.sname;
const email = req.body.email;
var subscribingUser = {
firstName: firstName,
lastName: lastName,
email: email
}
const run = async () => {
const response = await client.lists.addListMember("0790pipi4a766d", {
email_address: subscribingUser.email,
status: "subscribed",
merge_fields: {
FNAME: subscribingUser.firstName,
LNAME: subscribingUser.lastName
}
});
console.log(response.status);
}
// IF YOU COME BACK, SOMETHING IS NOT RIGHT HERE, THE CONDITIONAL FLOW DOESN'T WORK. FIND THE SOLUTION.
if (response.status === "subscribed") {
res.send("<h1>Success</h1>");
run();
} else {
res.send("<h1>Something went wrong. Give it another go.</h1>");
run();
}
});
app.listen(port, () => {
console.log(`Application currently running on port ${port}`);
});
and nothing happened and after a while error says the response is not defined.
Would be very glad if you could refer me to another similar post. I couldn't find one. Thanks!