4

using axios in a vue.js project, I'm having issues call the mailchimp API to sign up an email for a newsletter.

axios.post('//myappname.us9.list-manage.com/subscribe/post-json', { 
     u: 'abcde',
    id: '12345',
    EMAIL: this.email
}).then(response => {
    console.log(response)
}).catch(response => {
   console.log(response)
})

Results an error in the OPTIONS preflight:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

How can I bypass these CORS issues? I tried with JSONP, that semi-works. My request come through, but I can't handle the response very well, as I don't really get a response, but just an error, as the response isn't a JSONP response, but a ordinary JSON response.

I used the vue-jsonp package for the jsonp test.

Any pinpointers? Would be much appreciated. Thanks.

Qar
  • 1,746
  • 3
  • 17
  • 24
  • 2
    It isn't safe to make secure api requests from JavaScript. For example, how do you store your api token? Instead, you should make a request to your own server which in turn makes the api request to mailchimp and returns the results. – craig_h Jun 20 '17 at 13:33
  • 3
    No security is needed for this. It's a newsletter sign up. It does the same as mailchimps embed form. – Qar Jun 20 '17 at 13:42
  • Regardless, mailchimp hasn't allowed CORS requests, so you will still need to make these through your server. – craig_h Jun 20 '17 at 14:26

0 Answers0