CODE
const addSubscriber = function addSubscriber(user) {
console.log('IN ADD SUBSCRIBER');
return axios({
method: 'post',
url: `https://${mailchimpDC}.api.mailchimp.com/3.0/lists/${mailchimpListId}/members`,
data: {
email_address: user.email,
status: "subscribed",
merge_fields: {
FNAME: user.name.firstName,
LNAME: user.name.lastName,
ID: user._id,
},
},
headers: `Authorization: apikey ${mailchimpAPIKey}`,
})
.then(res => {
console.log('res', res);
})
.catch((err) => {
console.log('err', err);
})
};
OUTPUTは、最後にそれを考え出しました。承認ヘッダーの形式が正しくありませんでした。承認はヘッダーオブジェクトの下のキーである必要があります。私はContent-Typeも追加しました。今はすべてが動作します!
const addSubscriber = function addSubscriber(user) {
console.log('IN ADD SUBSCRIBER');
return axios({
method: 'post',
url: `https://${mailchimpDC}.api.mailchimp.com/3.0/lists/${mailchimpListId}/members`,
data: {
email_address: user.email,
status: "subscribed",
merge_fields: {
FNAME: user.name.firstName,
LNAME: user.name.lastName,
ID: user._id,
},
},
headers: {
'Content-Type': 'application/json',
Authorization: `apikey ${mailchimpAPIKey}`,
},
})
.then(res => {
console.log('res', res);
})
.catch((err) => {
console.log('err with mailchimp request', err);
})
};