3

Pasted below is my code. According to Mailchimp's auth docs, it's just basic auth. Am I missing something?

router.post('/subscribe', function(req, res, next) {
    const email = req.body.email;
    const auth = 'Basic ' + new Buffer(`anystring:${mailchimpApiKey}`).toString('base64');
    const data = JSON.stringify({
        email_address: email,
        status: 'subscribed',
        timestamp_signup: Date.now()
    });

    axios.post(`${mailchimpApiUrl}/${mailchimpListId}/members`, {
        header: {
            'Authorization': auth,
            'content-type': 'application/json'
        },
        data
    })
    .then((res) => {
        console.log('response: ', res);
    })
    .catch((err) => {
        console.log('error: ', err);
    })

    res.send('hit subscribe endpoint!');
})
ekad
  • 14,436
  • 26
  • 44
  • 46
Alex Ting
  • 31
  • 2

0 Answers0