function emailSubscribe() {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)
{
const data = {
members: [
{
email_address: document.getElementsByClassName("email input"),
status: 'subscribed'
}
]
};
const postData = JSON.stringify(data);
fetch('https://us19.api.mailchimp.com/3.0/lists/mylist', {
method: 'POST',
mode: 'no-cors',
headers: {
Authorization: 'auth apikey-us19',
},
body: postData
})
.then(function(response) {
response.statusCode === 200 ?
alert("You have been successfully subscribed to StreamIntra. An email should be arriving shortly.") :
alert("An error has occurred, please try again later.")
.catch(console.log(response))
})
} else {
alert("You have entered an invalid email address!")
}
}
I have this function that I call by a submit button on my local express server but it keeps giving me a 401 error (incorrect api key). I've read the api and check my api key, everything looks fine. I've also tried encoding and sending the key, still nothing. I've looked at this link: MailChimp. Error 401 (Unauthorized) when sending a request for adding a new list member but an answer doesn't seem to be provided. He mentions that mailchimp doesn't work with cors, but I'm running in no-cors mode. Any way to validate my request so I don't get the error?