1

I'm tryng to authenticate with mailchimp api in order to perform some api calls. I'm using Axios and I try some different codes but i'm still having the same error on authentication (i intercept the catch but i not receive a real error code)

I'm using axios with standard get notation. i tried also to add header autentication or to add explicit base64 encoded usr:passwd You can see at: https://codesandbox.io/embed/mailchimp-v3-test-zyfm8

try {
      const response = await axios.get(url, {
        auth: { username: usr, password: apikey }
      });

      if (response) {
        console.log(response);
      }
    } catch (e) {
      console.log(e);
    }

Test with base64

const credentials = btoa(username + ':' + password);
  const basicAuth = 'Basic ' + credentials;
  axios.post(session_url, {
    headers: { 'Authorization': + basicAuth }
  }).then(function(response) {
    console.log('Authenticated');
  }).catch(function(error) {
    console.log('Error on Authentication');
  });

i receive a "error {}" console log, not the success response i expect


the following comment i received i think solve: "Because of the potential security risks associated with exposing account API key, Mailchimp does not support client-side implementation of our API using CORS requests”

Daniele M
  • 21
  • 3
  • that doesn't look like how you do basic auth - show the part where you tried some base64 - that sounds right – Bravo Oct 24 '19 at 08:00
  • @Bravo passing such an `auth` object in the parameters is a valid way to do this in axios, it will automatically create the necessary Authorization header from that. – 04FS Oct 24 '19 at 08:01
  • Your codesandbox example shows a CORS error in console, but I can’t tell if that is just due to the test setup (it might not be the right origin domain here, plus it tries to request `https://us4.api.mailchimp.com/3.0/lists/xxx` with the _literal_ `xxx` at the end here.) – 04FS Oct 24 '19 at 08:05
  • @04FS - OK, good to know – Bravo Oct 24 '19 at 08:08
  • https://mailchimp.com/developer/guides/get-started-with-mailchimp-api-3/: _“Because of the potential security risks associated with exposing account API key, Mailchimp does not support client-side implementation of our API using CORS requests”_ - that explains why it won’t work in your codesandbox example at least then, I suppose. Question then is, are you actually doing your tests using server-side JS (node.js) here …? – 04FS Oct 24 '19 at 08:14

0 Answers0