Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error code 1, Access Denied #15

Closed
pruggirello opened this issue Feb 25, 2021 · 1 comment
Closed

Error code 1, Access Denied #15

pruggirello opened this issue Feb 25, 2021 · 1 comment

Comments

@pruggirello
Copy link

Hey! Thanks for making this api. I had given up last year after having been unable to find anything useable in my React application. I have kind of a weird issue, I installed the api and used it once with success. I was able to add my email to my group and verified it inside my MailerLite account. When I went to make a component that did that (it was originally just raw html inside another component), I got an error code saying access was denied. Specifically, it says:

"Access to XMLHttpRequest at 'https://api.mailerlite.com/api/v2/groups/104625980/subscribers' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field x-mailerlite-apikey is not allowed by Access-Control-Allow-Headers in preflight response."

Here is my MailerLite.js file:
const MailerLite = require('mailerlite-api-v2-node').default;
var apikey = example_api_key;
const mailerlite = MailerLite(apikey);
export default mailerlite;

Here is the function I am using to post my new subscriber:
addEmailSub = () => {
var email = document.getElementById("email").value;
mailerlite.addSubscriberToGroup(104625980, email);
}

Any input would be appreciated!

@MrJibus
Copy link

MrJibus commented Mar 4, 2021

According to : https://developers.mailerlite.com/docs/authentication

API key is designed for server-side usage and it cannot be used directly on the client side making AJAX calls because it will be exposed publicly. So it is forbidden due to security concerns.

@zygos zygos closed this as completed Mar 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants