I have seen several other questions like this, but they do not solve the issue. I used MailChimp's API to make a simple call to add a member to my mailing list when they sign up.
However when I test, I get a 401 unauthorized and the API complains of no API key submitted. When I inspect the request in Chrome, I don't see any Authorization header. Here is my code:
const formData = {
email_address: this.emailControl.value,
status: 'subscribed',
merge_fields: {
NAME: this.nameControl.value
}
};
const header = new HttpHeaders({
'Authorization': 'apikey:' + environment.mailChimpApiKey
});
this.http.post(this.mailChimpUrl, formData, {
headers: header,
observe: 'response'
}).subscribe(response => {
console.log('response', response);
if (response.status === 200) {
this.submitted = true;
}
});
I have checked and double-checked the HttpClient.post method signature, and how the MailChimp API expects to receive the Auth header. It seems like I'm doing everything right, so why isn't Angular setting the header?
I am noticing that the value changes only for the Access-Control-Request-Headers
when I set optional headers. Am I reading the chrome console wrong?
Angular version: 5.2.4